Edge Caching caches your REST API responses on globally distributed edge locations (CDN). Edge caching decreases the global latency up to 70%.
By default, edge caching is disabled for a new database. You can enable it in database details page in the Upstash Console. Enable edge caching when:
- Your Redis clients are globally distributed to multiple regions.
- You need low latency globally.
- You access your Redis from edge functions (Cloudflare, Fastly).
Edge caching is only available for the REST API. It is not supported in free tier.
In your database detail page click on the ⚙️ icon next to
Edge Caching Enabled field. Once enabled, click on the
REST APIbutton to see the Edge URL. Use the Edge URL in your REST calls.
The cached responses expire in 30 seconds by default. You can override this by setting
Cache-Control: max-age=<seconds> in your header. You can set max 900 (15 minutes) as max-age. You can also
Cache-Control: no-cache if you want to skip caching the response for a request.
curl https://edge-us1-merry-cat-32748.upstash.io/get/foo \-H "Authorization: Bearer 2553feg6a2ddsfdsc842h2a08efe9934"-H "Cache-Control: max-age=50"
The first request to the above URL will fetch the response from the Upstash Redis. The next requests will be fetched from edge locations. The cached responses will expire in 50 seconds at each edge location.
Only GET requests are supported in Edge Caching. As a result, write/update commands and some read commands (e.g. PIPELINE) are not supported as they work with POST request. You can use the standard REST URL for them.
Edge caching has an additional cost. For more info please see Edge Caching Pricing section.