API Gateway Caching
What you'll learn: How to use API Gateway caching to store frequently requested responses and dramatically reduce backend load.
The Core Idea
API Gateway caching stores copies of your API responses for a configurable time period. When a request comes in that matches a cached entry, the gateway returns the stored response immediately—without calling your backend services. Think of it like a library keeping frequently borrowed books at the front desk instead of making you walk to the stacks every time.
This reduces the load on your backend (databases, functions, servers) and delivers responses much faster to users. It's particularly valuable for data that doesn't change frequently—like product catalogs, configuration settings, or weather forecasts.
How It Works
You enable caching at the stage level (remember API Gateway stages from lesson 532) and configure a time-to-live (TTL) duration—typically measured in seconds. Common TTL values range from 60 seconds to hours, depending on how fresh your data needs to be.
The gateway uses the request path and query parameters as cache keys by default. So /products?category=books gets cached separately from /products?category=electronics.
You can also configure per-method cache settings, allowing different endpoints to have different TTLs or bypass caching entirely for operations like POST or DELETE.
When to Use Caching
- Read-heavy APIs with stable data
- Public endpoints serving the same content to many users
- APIs with predictable traffic patterns
- Scenarios where eventual consistency is acceptable
Avoid caching for user-specific data unless you carefully manage cache keys, or for rapidly changing data where staleness causes problems.
Key Takeaway: API Gateway caching stores backend responses temporarily, reducing latency and backend load for frequently requested data—configure TTL and cache keys based on your data freshness requirements.