...
Table of Contents | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
Use this policy to save time when network is congested and proxy API response is delayedwith highly reoccurring and static responses to manage latency and response times, and reduce load on the proxy server. An incoming HTTP request to one of your Proxy endpoints returns the cached response after a specified time period.
For example, the following API request has the
In the policy settings, you specify the cache key parameters that HTTP requests map to and set the cache response time and refresh interval.
...
The policy supports using headers and query parameters to access the cache keys. The key is hashed with a SHA1 algorithm.Each Cached HTTP Response contains the following information:
Original HTTP Response Object for preserving the flow of handling HTTP responses in the Gateway Resource.
...
.
Expired caches cannot be accessed and new entries overwrite any existing ones.
...
.
Limitations
Each response cache can only contain 85 MB. The policy always returns the response, but any data over the limit renders the payload incomplete.
A response cache is not effective to use for POST and PUT HTTP methods because these operations are meant to alter the state of data, and hence should not be cached.
...
Parameter Name | Description | Default Value |
---|---|---|
Label | Required. The name for the API policy. | HTTP Respone Cache |
When this policy should be applied | An expression-enabled field that determines the condition to be fulfilled for the API policy to execute. For example, if the value in this field is | N/A |
Cache Interval | The time period of the current cache before it is refreshed. | 1 |
Time Unit | The time unit for the Cache Interval value. | Hour |
Use HTTP Request Headers to Create Cache Keys | Enables the use of specific headers to identify a cache. | Unselected |
Use HTTP Request Query Parameter to Create Cache Keys | Enables the use of query parameters to identify a cache. | Unselected |
Status | Specifies whether the API policy is enabled or disabled. | Enabled |
Example
The policy supports using headers and query parameters to access the cache keys:
We can recommend that header and query string keys can be configured for caching HTTP responses with unique key-value pairs. For example in a REST GET endpoint that multiplies two integers:
Code Block GET /gateway/proxy/multiply?intA=[valueA]&intB=[valueB]
Configuring the policy to use header keys intA and intB to cache policies for every key-value pair that has query strings with intA and intB.
For example, the following GET requests will have cached responses when using the HTTP Response Cache policy:
Code Block /gateway/proxy/multiply?intA=5&intB=5 /gateway/proxy/multiply?intA=2&intB=2 /gateway/proxy/multiply?intA=3&intB=1
The following HTTP responses will be cached so that the proxied server does not need to perform the calculation:
Code Block Response 1 { "operation": "5 x 5", "result": 25 } Response 2 { "operation": "2 x 2", "result": 4 } Response 3 { "operation": "3 x 1", "result": 3 }