Edge Caching for Web Services
Serve static content from a global edge cache for faster delivery.
Render provides edge caching for static assets (documents, images, etc.) served by paid web services. With edge caching enabled, you can speed up response times and reduce load on your web service:
Edge caching is powered by the same global CDN as Render static sites.
Setup
Edge caching is not available for free web services.
-
In the Render Dashboard, open your web service's Settings page and scroll down to the Edge Caching section:
-
Toggle the switch. A confirmation dialog appears.
-
Review the notices in the dialog, then click Confirm and enable.
You're all set! Render begins caching your web service's cache-eligible responses.
How edge caching works
Whenever a client sends an HTTP request to your cache-enabled web service, Render determines whether the request is eligible to serve from the edge cache. (For details, see Cache eligibility.)
If the request is cache-eligible, Render checks the edge cache for the corresponding resource.
-
If the requested resource is in the cache (and the entry isn't stale), Render serves the cached version:
In this case, the request never reaches your web service. This speeds up the response and reduces load.
-
Otherwise, Render fetches the resource from your web service and—if it's also cache-eligible—caches it for future requests:
Cache eligibility
When serving a request from your web service, Render uses the following logic to determine whether the response can be cached for future requests:
* See details below.
To summarize, all of the following must be true for a response to be cache-eligible:
- The originating request must use the
GET
orHEAD
HTTP method. - The requested resource must have a cache-eligible file extension.
- The response must either include a
Cache-Control
header that allows caching or have a default-cacheable status code. - Additionally, the response must not include a
Set-Cookie
header.
Cache-eligible file extensions
A requested resource must have one of the following file extensions to be cache-eligible:
7z
avi
avif
bin
bmp
bz2
class
css
csv
dmg
doc
docx
eot
ejs
eps
exe
flac
gif
gz
ico
iso
jar
jpeg
jpg
js
mid
midi
mkv
mp3
mp4
ogg
otf
pdf
pict
pls
png
ppt
pptx
ps
rar
svg
svgz
swf
tar
tif
tiff
ttf
webm
webp
woff
woff2
xls
xlsx
zip
zst
Default-cacheable status codes
If your web service returns a cache-eligible response without a Cache-Control
header, Render caches the response if it has one of the following status codes (and applies the corresponding default TTL):
Status code | Default TTL |
---|---|
200, 206, 301 | 120 minutes |
302, 303 | 20 minutes |
404, 410 | 3 minutes |
Invalidation and expiration
To help ensure that clients receive up-to-date content, Render invalidates edge cache entries in the following scenarios:
Scenario | Description |
---|---|
New deploys |
Each time you deploy a new version of your web service, Render purges all of its associated edge cache entries. This way, deployed changes are reflected to clients as quickly as possible. |
TTL expiration |
Each cache entry has a corresponding time-to-live (TTL). When an entry's TTL expires, the entry is considered stale. The next request for a stale entry is sent to your web service, which refreshes the entry. |
Manual purge |
You can trigger a cache purge for your web service from its Settings page in the Render Dashboard: As with a new deploy, this purges all of your web service's associated edge cache entries. |
Setting Cache-Control
headers
You can customize Render's edge caching behavior for a particular resource by including a Cache-Control
(or CDN-Cache-Control
) header in your web service's response:
Cache-Control: public, max-age=7200
New to cache control headers?
Learn more about supported response directives.
Customization | Description |
---|---|
Set a TTL (time-to-live) |
Do both of the following in your response's
http
|
Disable caching |
Do either of the following in your response's
http
|
Set revalidation behavior |
Include a combination of the http
|
Precedence rules
Render applies the following precedence rules to cache control headers:
- The
CDN-Cache-Control
header takes precedence over theCache-Control
header if both are present. - The
s-maxage
directive takes precedence over themax-age
directive if both are present.
Inspecting cache behavior
Each response from a cache-enabled web service includes a CF-Cache-Status
header:
CF-Cache-Status: HIT
The value of this header indicates whether the response interacted with the edge cache and in what way. The most common values are:
Value | Description |
---|---|
|
The response was served from the edge cache. |
|
The response was not found in the edge cache. It was served from your web service and cached if eligible. |
|
Some element of the incoming HTTP request was not cache-eligible, and the response was served from your web service. Most commonly indicates one of the following:
|
|
The response was found in the edge cache, but its TTL had expired. It was served from your web service and the edge cache was updated with the new response. |
|
The response was served directly from your web service and was not stored in the edge cache, usually for one of the following reasons:
|