Course contentsShow
← Cloud and Infrastructure
Lesson 536 of 2,98910. API Gateway and Event-Driven PatternsFree lesson

API Gateway Caching

Configure response caching to reduce backend load and improve API performance with TTL and cache key configuration.

API Gateway Caching

You'll learn how to configure response caching in API Gateway to reduce backend load and speed up API responses.

What Is API Gateway Caching?

API Gateway caching stores responses from your backend services for a specified period. When identical requests arrive, the gateway serves the cached response instead of forwarding the request to your backend. This reduces latency for clients and decreases the workload on your backend infrastructure.

Think of it like a restaurant server remembering a regular customer's "usual order" instead of running to the kitchen every single time.

How Caching Works

When you enable caching:

  1. First request hits the backend, response is stored in cache
  2. Subsequent identical requests are served directly from cache
  3. Cache expires after the TTL (Time To Live) period
  4. Next request fetches fresh data and updates the cache

Key Configuration Elements

Time To Live (TTL)

TTL defines how long (in seconds) a response remains cached before expiring. Short TTLs (e.g., 60 seconds) keep data fresher but require more backend calls. Long TTLs (e.g., 3600 seconds/1 hour) maximize performance but may serve stale data.

Cache Key Configuration

The cache key determines which request parameters make a request "unique." Common cache key components include:

  • Path parameters (/users/{userId})
  • Query strings (?category=books&sort=price)
  • Request headers (e.g., Accept-Language)

Two requests are considered identical only if their cache keys match exactly.

Cache Capacity

Gateway caches have size limits (typically measured in GB). Popular responses stay cached while less-accessed ones are evicted.

Key Takeaway: API Gateway caching reduces backend load and improves performance by storing responses based on TTL and cache key configuration—balance freshness requirements against performance gains when setting TTL values.