Caching
Caching is the process of storing files on edge servers to improve the response time when serving those files to customers. By storing files closer to users, caching reduces the time it takes for data to travel across the network, commonly known as latency.
By default, CIS caches static files, which include many types of image and text files (non-HTML). The cache includes files only from your websites and doesn't cover third-party resources, such as those from social networking sites. Currently, CIS does not cache based on MIME type.
CIS doesn't cache HTML files by default because they are generally considered dynamic. However, if static HTML can be clearly distinguished from dynamic HTML, it is possible to cache HTML files by using page rules.
Cached files have a specified expiration time, called Time-to-Live (TTL), after which they are purged from the cache. You can also manually purge files from the cache at any time. After files are purged, CIS goes back to your origin server to reload the files and update the cache with the most recent versions.
For detailed information on cache settings and options, see Using page rules with caching.
Default caching behavior
CIS caches static content based on your visitors' locations, the CIS data center they connect to, and how frequently the resource is requested at that data center.
Caching occurs only within the CIS data center that serves the request. The following resources aren't cached by CIS:
- Off-site or third-party resources
- Content hosted on DNS records that aren't proxied
By default, CIS respects the origin web server’s cache headers unless an edge cache TTL page rule overrides them:
- CIS doesn't cache resources if the
cache-control
header is set toprivate
,no-store
,no-cache
, ormax-age=0
, or if a cookie is present in the response. - CIS caches resources if
cache-control
ispublic
with amax-age
greater than 0, or if the expires header specifies a future date. - When both
max-age
andexpires
headers are set,max-age
takes precedence.
When both the cache-control
directive and the expires
headers aren't present, CIS caches certain HTTP response codes with the following default edge cache TTL:
Response code | TTL |
---|---|
200, 206, 301 | 120 m |
302, 303 | 20 m |
404, 410 | 3 m |
403 | 1 m |
CIS provides several options to customize caching:
- Set caching behavior for individual URLs by using CIS page rules.
- Use CIS edge functions or the API to customize caching.
- Adjust caching levels, TTL, and more through the CIS CLI.
The maximum file size that CIS caches is 512 MB for Trial and Standard Next customers, and 5 GB for Enterprise customers. Enterprise customers can request caching of larger files by opening a support case.
File extensions cached by default
CIS uses file extensions to cache content. The following file extensions are cached automatically:
File extensions | |||
---|---|---|---|
bmp class css csv doc docx ejs eot eps |
gif ico jar jpg js mid midi otf pdf |
pict pls png ppt pptx ps svg svgz swf |
tif tiff ttf webp woff woff2 xls xlsx |
CIS doesn't cache content based on MIME type, and by default, it doesn't cache HTML pages. However, it does automatically cache your website's robots.txt
file. To cache extra content, such as HTML pages, you can set up custom page
rules to control what gets cached.
Serving stale content
Serve stale content keeps a limited version of the site online if the server goes down. Even if the content expires, CIS continues serving cached content to users when origin servers are offline.
Understanding CIS cache responses
The output of the CF-Cache-Status
header shows whether a resource is cached.
Response code | Definition |
---|---|
HIT |
The resource was found in the CIS cache. |
MISS |
The resource wasn't found in the CIS cache and was served from the origin web server. |
EXPIRED |
The resource was found in the cache but has since expired and was served from the origin web server. |
STALE |
The resource was served from cache, but is expired. CIS wasn't able to contact the origin to retrieve the updated resource. |
BYPASS |
The origin server instructed CIS to bypass the cache by using a cache-control header set to no-cache , private , or max-age=0 . BYPASS is returned when you enable origin cache-control .
CIS also sets BYPASS when your origin web server sends cookies in the response header. |
REVALIDATED |
The resource is served from cache, but is stale. The resource was revalidated by either an If-Modified-Since header or an If-None-Match header. |
UPDATING |
The resource was served from the cache, but is expired. The resource is being updated by the origin web server. UPDATING is typically seen only for popular cached resources. |
DYNAMIC |
The resource wasn't cached by default and your current CIS caching configuration doesn't instruct CIS to cache the resource. Instead, the resource was requested from the origin web server. Use page rules to implement custom caching options. |
Using query string sorting
Enterprise Only: CIS treats URLs with query strings in different orders as separate files in the cache. For example, if one user requests:
/video/123456?title=0&byline=0&portrait=0&color=987654
and another requests:
/video/123456?byline=0&color=987654&portrait=0&title=0
CIS fetches the file from the origin again, even if it’s already cached.
The Query String Sort feature sorts query strings "before" caching, increasing cache hit rates. You can enable Query String Sort by using the toggle on the Caching page.