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:

Diagram illustrating an edge cache hit

Edge caching is powered by the same global CDN as Render static sites.

Setup

Edge caching is not available for free web services.

  1. In the Render Dashboard, open your web service's Settings page and scroll down to the Edge Caching section:

    Enabling edge caching in the Render Dashboard

  2. Toggle the switch. A confirmation dialog appears.

  3. 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:

    Diagram illustrating an edge cache hit

    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:

    Diagram illustrating an edge cache miss

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:

Yep!
Nope, some other
HTTP method.
Yep!
Nope.
Yep!
Header is
not present.
Header is present, but
it disallows caching.
Yep!
Nope.
Is the request method
either GET or HEAD?
Is the request for a
resource with a
cache-eligible file extension*
(such as .jpg or .pdf)?
Does the response include
a Cache-Control header
that allows caching?
Is the HTTP status code
cacheable by default*?

Response is not
cache-eligible.

Response is
cache-eligible!

* 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 or HEAD 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 codeDefault TTL
200, 206, 301120 minutes
302, 30320 minutes
404, 4103 minutes

Invalidation and expiration

To help ensure that clients receive up-to-date content, Render invalidates edge cache entries in the following scenarios:

ScenarioDescription

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:

Triggering a cache purge 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:

http
Cache-Control: public, max-age=7200

New to cache control headers?

Learn more about supported response directives.

CustomizationDescription

Set a TTL (time-to-live)

Do both of the following in your response's Cache-Control header:

  • Include the public directive.
  • Set the max-age or s-maxage directive to a value greater than 0.
http
Cache-Control: public, max-age=3600

Disable caching

Do either of the following in your response's Cache-Control header:

  • Include the no-cache, no-store, or private directive.
  • Set the max-age or s-maxage directive to 0.
http
Cache-Control: no-cache

Set revalidation behavior

Include a combination of the must-revalidate, stale-while-revalidate, and stale-if-error directives.

http
Cache-Control: stale-while-revalidate=60, stale-if-error=3600, public, max-age=1200

Precedence rules

Render applies the following precedence rules to cache control headers:

  • The CDN-Cache-Control header takes precedence over the Cache-Control header if both are present.
  • The s-maxage directive takes precedence over the max-age directive if both are present.

Inspecting cache behavior

Each response from a cache-enabled web service includes a CF-Cache-Status header:

http
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:

ValueDescription

HIT

The response was served from the edge cache.

MISS

The response was not found in the edge cache. It was served from your web service and cached if eligible.

DYNAMIC

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:

EXPIRED

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.

BYPASS

The response was served directly from your web service and was not stored in the edge cache, usually for one of the following reasons:

  • The response included a Cache-Control header that disabled caching.
  • The response did not include a Cache-Control header, and it returned a status code that is not default-cacheable.
  • The response included a Set-Cookie header.