You're using the query parameter w as a cache key. Apigee Edge checks the value of the query parameter w whenever a request is received. If a valid (that
is, non-expired) response is present in the cache, then the cached response message is returned to the requesting client.

Now imagine that you have a ResponseCache policy configured as follows.

The first time the API proxy receives a request message for the following URL, the response is cached. On the second request within 10 minutes, a cache lookup occurs -- the cached
response is returned to the app with no request forwarded to the backend service.

http://{org_name}-test.apigee.net/weather/forecastrss?w=23424778

HTTP headers and query parameters are automatically populated as variables when a request is received. Any HTTP header is available as request.header.{header_name},
for example request.header.user-agent. Any query parameter is available as request.queryparam.{queryparam_name}, for example
request.queryparam.action.

The following example shows how to have the cache lookup skipped and have the cache refreshed.

The optional SkipCacheLookup condition (if configured) is evaluated in the request path. If the condition evaluates to true, then the cache look up is skipped and the cache is
refreshed.

A common use of conditional cache refresh is a condition that defines a specific HTTP header that causes the condition to evaluate to true. A scripted client application could be
configured to periodically submit a request with the appropriate HTTP header, explicitly causing the response cache to refresh.

<CacheKey> constructs the name of each piece of data stored in the cache. The key is often set using a value from entity headers or query params. In
those cases, you would have the element's ref attribute specify a variable containing the

At runtime, <KeyFragment> values are prepended with either the <Scope> element value or <Prefix> value. For
example, the following results in a cache key of UserToken__apiAccessToken__<value_of_client_id>:

<Scope> element

Enumeration used to construct a prefix for a cache key when a <Prefix> element is not provided in the <CacheKey> element.

<Scope>scope_enumeration</Scope>

Default:

"Exclusive"

Presence:

Optional

Type:

String

The <Scope> setting determines a cache key that is prepended according to the <Scope> value. For example, a cache key would take
the following form when scope is set to Exclusive : orgName__envName__apiProxyName__deployedRevisionNumber__proxy|TargetName__ [ serializedCacheKey ].

If a <Prefix> element is present in <CacheKey>, it supercedes a <Scope> element value. Valid values include the
enumerations below.

You use the <Scope> element in conjunction with <CacheKey> and <Prefix>. For more information, see
Working with cache keys.

Acceptable values

Scope Value

Description

Global

Cache key is shared across all API proxies deployed in the environment. Cache key is prepended in the form orgName __ envName __.

If you define a <CacheKey> entry with the <KeyFragment> apiAccessToken and a <Global> scope, each entry is stored as
orgName__envName__apiAccessToken, followed by the serialized value of the access token. For an API proxy deployed in an environment called 'test' in an
organization called 'apifactory', access tokens would be stored under the following cache key: apifactory__test__apiAccessToken.

APIProxy

API proxy name is used as the prefix.

Cache key is prepended in the form orgName__envName__apiProxyName.

Proxy

ProxyEndpoint configuration is used as the prefix.

Cache key is prepended in the form orgName__envName__apiProxyName__deployedRevisionNumber__proxyEndpointName .

Target

TargetEndpoint configuration is used as the prefix.

Cache key prepended in the form orgName__envName__apiProxyName__deployedRevisionNumber__targetEndpointName .

Exclusive

Default. This is the most specific, and therefore presents minimal risk of namespace collisions within a given cache.

Prefix is one of two forms:

If the policy is attached to the ProxyEndpoint flow, prefix is of the form ApiProxyName_ProxyEndpointName.

If the policy is attached at TargetEndpoint, prefix is of the form ApiProxyName_TargetName.

Cache key prepended in the form orgName__envName__apiProxyName__deployedRevisionNumber__proxyNameITargetName

For example, the full string might look like this:

apifactory__test__weatherapi__16__default__apiAccessToken

.

<SkipCacheLookup> element

Defines an expression that, if it evaluates to true at runtime, specifies that cache lookup should be skipped and the cache should be refreshed.

<SkipCacheLookup>variable_condition_expression</SkipCacheLookup>

Default:

N/A

Presence:

Optional

Type:

String

From the following example, if the bypass-cache variable is set to true in an incoming header, cache lookup is skipped and the cache is refreshed.

Attributes

Attribute

Description

Default

Presence

Type

ref

Variable with the timeout value.

N/A

Optional

String

Usage notes

ResponseCache can be configured to save and periodically refresh copies of response messages. As apps make requests to the same URI, Apigee Edge can be configured to return cached
responses, rather than forwarding those requests to the backend server.

ResponseCache is commonly used when backend data is updated only periodically. For example, an API that exposes weather report data might only refresh the weather data once every ten
minutes. By returning cached responses and refreshing once every ten minutes, ResponseCache decreases the number of request reaching the backend, and also eliminates a network hop for a
significant portion of requests to the API.

There are two main benefits to ResponseCache:

Reduced latency: The request is satisfied from the cache (removing a network hop), so the response is returned in a shorter time, making the API more responsive.

Reduced network traffic: Representations are reused, so the impact of processing duplicate or redundant requests is reduced. ResponseCache reduces the amount of
bandwidth consumed overall.

Unlike other policies, a ResponseCache policy must be attached to both request and response paths within a Flow.

You can configure the ResponseCache proxy to also look at certain HTTP response caching headers and take appropriate actions according to the directives of those headers. For example,
on responses from backend targets, Edge supports the Cache-Control header, which can be used to control the maximum age of a cached response, among other directives. For
more information, see HTTP response caching.

The name attribute for this policy is restricted to these characters: A-Z0-9._\-$ %. However, the Management UI enforces additional restrictions, such as
automatically removing characters that are not alphanumeric.

Cached response messages are returned to requesting apps based on request message keys configured in the policy. At runtime, Apigee Edge inspects request messages for a 'key' that you
specify. A key is a piece of information (such as query parameter) common to all request messages whose responses you need to cache. When a key match occurs, Edge returns the cached
response, instead of forwarding the request to the backend service.

Attaching a ResponseCache policy

The ResponseCache policy type is unique in that it must be attached to both the request and response Flow in an API proxy.

ResponseCache policies are usually attached to the ProxyEndpoint PreFlow Request and Response, as in this example: