API / APIGEE Gateway Interview Questions
What is response caching in Apigee and how do you configure the ResponseCache policy?
The ResponseCache policy stores successful backend responses in Apigee's in-memory cache. When an identical subsequent request arrives within the cache TTL, Apigee serves the cached response directly without contacting the backend at all. This reduces backend load and improves latency.
<!-- ResponseCache policy --> <ResponseCache name="ResponseCache"> <!-- How to build the cache key --> <CacheKey> <Prefix>weather</Prefix> <!-- Cache key includes the city query parameter --> <KeyFragment ref="request.queryparam.city" /> </CacheKey> <!-- How long to cache the response --> <ExpirySettings> <TimeoutInSec>300</TimeoutInSec> <!-- 5 minutes --> </ExpirySettings> <!-- Skip caching if the client sends Cache-Control: no-cache --> <SkipCacheLookup>request.header.cache-control = "no-cache"</SkipCacheLookup> </ResponseCache> <!-- Placement: ResponseCache appears in BOTH: 1. ProxyEndpoint PreFlow Request (to check for cache hit) 2. ProxyEndpoint PostFlow Response (to populate the cache on cache miss) Apigee handles the dual role automatically with this single policy --> <!-- Flow variables after policy executes: responsecache.ResponseCache.cachehit -- true/false responsecache.ResponseCache.cachekey -- the computed cache key -->
| Policy | Scope | Purpose |
|---|---|---|
| ResponseCache | Full response body | Cache entire response to avoid backend calls |
| LookupCache | Arbitrary values | Read arbitrary data from cache (used with PopulateCache) |
| PopulateCache | Arbitrary values | Write arbitrary data into a named cache |
| InvalidateCache | Arbitrary values | Explicitly remove entries from cache |
More Related questions...