Skip to main content
Feedback

Cache policy

Updated 22 July 2026

The cache policy enables you to cache the upstream response (content, status, and headers) and avoid subsequent calls to the backend.

This policy relies on a cache resource that you define at the API level and lets the underlying cache system follow the API lifecycle (stop / start). The system automatically creates the cache resource when you attach the cache policy rule to an API.

You can bypass cache by adding a cache=BY_PASS query parameter or by providing an X-Gravitee-Cache=BY_PASS HTTP header.

note

If you have a multi-node Gateway cluster, each node caches the API request because the cache is JVM-centric.

Timing

On RequestOn Response
X

Configuration

PropertyRequiredDescriptionTypeDefault
cacheNameyesThe cache resource used to store the element.string
keynoThe key used to store the element (supports EL). For POST requests, the key can also use fields or hashes from the request body.string
timeToLiveSecondsyesTime to live of the element in cache.integer600 (10 minutes)
methodsnoThe method to cache. Add POST to cache POST responses.array of strings[GET,OPTIONS,HEAD]
responseConditionnoAdd an extra condition (with Expression Language) based on the response to activate cache. For example, use {#upstreamResponse.status == 200} to only cache 200 responses status. If you do not specify a responseCondition, the policy caches all 2xx responses by default.string
useResponseCacheHeadersnoTime to live based on 'Cache-Control' and/or 'Expires' headers from backend response.booleanfalse
scopeyesCached response can be set for a single consumer (application) or for all applications. Caution If you use an \"API\" scope, the policy shares data between all consumers.API/APPLICATIONAPPLICATION

Examples

Key based on the productId query parameter:

"key": "{#request.params['productId']}"

Key based on the api-key of the consumer:

"key": "{#request.headers['X-Gravitee-Api-Key']}"

Key based on an API’s property and a query parameter:

"key": "{#properties['siteID']}-{#request.params['productId']}"

Configuration example:

"cache": {
"cacheName": "policy-cache",
"key": "{#request.params['productId']}",
"timeToLiveSeconds": 600,
"useResponseCacheHeaders": false,
"scope": "APPLICATION",
"methods": ["POST"],
"responseCondition": "{#upstreamResponse.status == 201}"
}

Cache key from POST request body

You can build the cache key from fields or hashes in a POST request body. Earlier versions evaluated body-based keys to null, so POST requests could not be cached with a body-based key.

Use this option for POST-based APIs, such as search or retrieval APIs that send the query in a JSON payload. Include POST in methods to cache POST responses.

Example: key based on a field in the JSON request body:

Key based on the DBSourceName field in the request body:

"key": "{#jsonPath(#request.content, '$.DBSourceName')}"

For this request body:

{"DBSourceName":"API_GETCRNINFO","Params":[{"FieldName":"PROFESSORBANNERID","Value":"A00020001","Operator":"="},{"FieldName":"TERMCODE","Value":"232420","Operator":"="}]}
note

The Gateway buffers the request body before the cache lookup. Buffering adds memory use and latency to requests that use a body-based key.

On this Page