Unify Logo Footer.svg
API Manager
Logo
Cache Policy

Cache Policy

Logo

3 mins READ

Store API responses temporarily so repeated requests are served from cache, reducing backend load and improving response times.

Overview

A Cache Policy stores API responses temporarily so that repeated requests can be served from cache rather than invoking the backend — improving response times, reducing backend load, and lowering infrastructure costs. Each cached response is stored for a fixed Time-to-Live (TTL); after the TTL expires, the next request fetches a fresh response and repopulates the cache.

cache.png
cache.png

Field Reference

Field

Description

Policy Name *

A unique identifier used across logs, dashboards, and API group configurations.

Tags

Custom labels to organize and filter the policy by environment, team, or functionality.

Cache Response *

Turn on to cache responses; the TTL and Cache Key fields appear once it is on.

Time-to-Live (TTL) Period *

How long a cached response is stored before it expires, defined in the unit specified by the Time Interval field. Available TTL limits depend on the current Cache Policy configuration — use the values shown in the policy editor.

Time Interval *

The unit of time for the TTL Period field. Available time-unit options depend on the current Cache Policy configuration — use the values shown in the policy editor.

Cache Key *

The unique key used to identify cached responses. Each cache key must be the name of a path parameter, query parameter, or header. Configuring multiple cache keys ensures distinct responses are cached separately.

cache-1.png
cache-1.png

How It Works

  1. Request arrives — The gateway receives an API request.

  2. Cache key generation — A cache key is constructed from the configured key parameters. If the request lacks any of them, it is not cached: it is neither served from nor stored in the cache.

  3. Cache lookup — The system checks whether a cached response exists for that key.

  4. Cache hit — If a cached response is found, it is returned immediately to the client. The backend is not called.

  5. Cache miss — If no cached response exists, the request is forwarded to the backend. If the backend returns a successful (200) response, it is stored in the cache before being returned to the client. Other responses are not cached.

  6. Cache expiration — After the TTL expires, the cached entry is removed. The next request will be a cache miss and repopulate the cache.

Attaching the Policy

Once a Cache Policy is created, attach it to an API Group, an API, or an access profile from its policy settings. When policies are attached at multiple levels, they run in the fixed order: access profile, then API, then API Group. Multiple policies attached at the same level can be reordered within that level’s policy settings.

Notes

  • Only cache idempotent responses — GET responses with stable, query-dependent data are good candidates; POST or mutation responses should not be cached.

  • Design cache keys carefully: if two different requests should return different data, their cache keys must differ. Include query parameters or caller-identifying headers in the key as appropriate.

  • Set TTL based on how frequently the underlying data changes — too long a TTL returns stale data; too short negates the caching benefit.

  • Monitor cache hit rate from the API Manager Insights dashboard to evaluate policy effectiveness and tune the TTL and cache key configuration.

FAQs

Does caching happen on the gateway or on the backend service?

Caching is managed by the API gateway. On a cache hit, the backend is not invoked at all — the gateway returns the stored response directly to the client.

What is the maximum TTL I can configure?

The maximum allowed TTL depends on the current Cache Policy configuration — check the limit shown in the policy editor’s TTL Period field. For data that changes more frequently, use a shorter TTL to balance freshness with performance.

How do I ensure different users receive different cached responses?

Include a caller-identifying attribute (such as an API key or a user-identifying header) in the Cache Key. This ensures each user's responses are cached and served separately.

What happens when the cache expires?

After the TTL expires, the cached entry is cleared. The next request for that cache key is a cache miss — it is forwarded to the backend, and the fresh response is cached again.

Do inbound policies run before a cache hit is returned?

Yes. Authentication, authorization, and any applicable inbound policies run before the gateway checks the response cache. Only successful 200 responses are cached.