Setting a Cache Expiry Time

Introduction

The Cache Expiry Time option of both Static and Static Push CDN services allows you to control cache system on our CDN edge servers. The Cache Expiry Time option determines for how long your content should be stored in the CDN cache.

Note that when your content expires in the CDN cache then (if requested) it is automatically pulled from your Origin Domain/Origin Storage again and the old CDN cache (if still exists) is replaced with the newly pulled content.

You have two options where you can set cache expiry time.

  1. In your application
  2. In CDN service settings

Please note that the option 1 overrides the option 2.

We recommend to set cache expiry time to far future to increase your cache hit ratio and to improve the CDN performance.

Setting cache expiry time in your application

You can set cache expiry time in your web server configuration.

This configuration is usually on a file type basis.

An example how to set cache expiry time in Apache .htaccess

# 30 DAYS
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
    Header add Cache-Control "max-age=2592000, public"
</FilesMatch>
 
# 2 DAYS
<FilesMatch "\.(xml|txt)$">
    Header add Cache-Control "max-age=172800, public, must-revalidate"
</FilesMatch>
 
# 2 HOURS
<FilesMatch "\.(html|htm)$">
    Header add Cache-Control "max-age=7200, public, must-revalidate"
</FilesMatch>

# NO CACHE
<FilesMatch "\.(html|htm)$">
    Header add Cache-Control "no-cache"
</FilesMatch>

An example how to set cache expiry time in Nginx

# 30 DAYS
location ~* \.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$ {
	add_header Cache-Control "max-age=2592000, public"
}
 
# 2 DAYS
location ~* \.(xml|txt)$ {
	add_header Cache-Control "max-age=172800, public, must-revalidate"
}
 
# 2 HOURS
location ~* \.(html|htm)$ {
	add_header Cache-Control "max-age=7200, public, must-revalidate"
}

# NO CACHE
location ~* \.(html|htm)$ {
	add_header Cache-Control "no-cache"
}

Setting cache expiry time in CDN service settings

You can set the Cache Expiry Time option on the Services/New Service and Services/Settings pages.

Setting cache expiry time in this way applies to all content of the particular CDN service.

If you have HTTP Pseudo Streaming option enabled then the Cache Expiry Time option applies also to your video files.

The If-Modified-Since validation

The If-Modified-Since validation increases CDN service performance by increasing its cache-hit ratio.

How it works

If a value (time) of the HTTP header Last-Modified in the CDN cache is the same as on the origin server then the corresponding content (CDN and origin) is considered to be identical.

Example

Assume that a file expires in the CDN cache. Assume also that the file still exists in the CDN cache and that it is requested by a visitor. If the file passes the If-Modified-Since validation then it is not pulled from the Origin Domain/Origin Storage again but the CDN edge server will stay using the old cache.

Notes

After changing origin HTTP headers you might need to purge your content from the CDN cache as it is cached with the old HTTP headers.

What next?

Read about the following topics.

Contact Us

  ______    _____     _____   
 /_   _//  |  ___||  /  ___|| 
   | ||    | ||__   | // __   
  _| ||    | ||__   | \\_\ || 
 /__//     |_____||  \____//  
 `--`      `-----`    `---`