Resources / Hosting
Edge caching for APIs: faster responses for less
When and how to cache API responses at the edge, how Cache-Control works, and what must never be cached.
A CDN in front of your API can answer repeated requests from a location near the user in milliseconds, without running your code. For read-heavy endpoints that's the cheapest performance win there is.
What to cache
- Public data that changes slowly: blog posts, product catalogs, exchange rates
- Expensive third-party lookups: geocoding, enrichment
- Anything identical for every caller
What never to cache
- Responses that depend on who's calling (anything with
Authorization, API keys or cookies) - Writes (POST, PUT, DELETE)
- Errors
How long?
Start with seconds to minutes. A 60-second cache on a busy endpoint already removes most of the load, and stale data never lives long. Purge the cache when you publish a new version.
In Wisp
Each GET endpoint has an Edge caching setting — off, or 1 second up to a day. Requests with credentials, draft requests and errors are never cached, cached hits don't use run credits, and publishing purges the cache automatically.
Build it with Wisp — describe an API, get it live.