Reverse Proxy Cache Headers

Reverse proxies such as Varnish are without question your best “bang for buck” when looking at performance improvements for your web application or publishing platform.

Your web page needs to send specific caching directives to the proxy to let it know how it should cache each page. The good news? FarCry is specifically designed to work with Reverse Proxies.

Webskin view decorators

To simplify adding cache headers to pages, we have added @@proxyCacheTimeout view decorators to webskins. This value specifies the number of seconds that a webskin should be cached for.

Add this to the top of any view to send the correct caching instructions to your reverse proxy.

<!--- @@proxyCacheTimeout: 120 --->

In the case of composite views (ie. those made up of several smaller web skins), the smallest timeout value specified when constructing a page is added to the header using the max-age and s-maxage headers, or as a set of no-cache headers if 0.

Note, the standard unit for cache timeout in FarCry is in minutes. Reverse proxy servers have better resolution, and proxy cache timeouts are in seconds.

Default Proxy Cache Timeout

By default, if no webskin specifies a proxy cache timeout, FarCry doesn’t add cache headers. You can set a site wide default cache header by using the defaultProxyCacheTimeout constructor setting.

For example, to default to a 2 minute cache farcryConstructor.cfm

<cfset this.defaultProxyCacheTimeout = 120 />

If you want FarCry to default to no-cache headers farcryConstructor.cfm

<cfset this.defaultProxyCacheTimeout = 0 />

Meta tags and response headers

As well as the typical response headers, META tags and an html comment are added to the page. These can help troubleshoot issues with reverse proxies.

Example meta tags

<META HTTP-EQUIV="Cache-Control" CONTENT="max-age=120,s-maxage=120" />
<!-- Page cached until: Mon, 28 Feb 2011 10:40:58 GMT+11 (120 seconds) -->

Example Cache Header

Cache-Control        max-age=120,s-maxage=120

We use max-age instead of Expires because of time zone complications. Effective use of Expires requires the correct time on the web server, the reverse proxy (or any proxies between the web server and the user), and the user’s own computer.

Example No Cache Header

Expires              Tue, 01 Jan 1985 00:00:01 GMT
Pragma               no-cache
cache-control        no-cache, no-store, must-revalidate

Proxy cache headers for use with reverse proxies and other proxy mechanisms were added in the 6.0.11 milestone release. This feature is available in all subsequent releases.

1 Like

We recently had a friend in trouble with their Varnish set up. The servers were on fire :fire: during peak traffic as just about everything was bypassing the Varnish servers.

Everything appeared to be set up just right except for a lone teaser webskin scheduled into an aside on every page in the site with a view decorator in place:

<!--- @@proxyCacheTimeout: 1 --->

All pages included this view. The smallest timeout value for every page was now proxyCacheTimeout: 1. Standard FarCry caching is based on minutes but proxy cache timeouts are counted in seconds.

Result? Every page was cached in Varnish for 1 second only :scream:

Ahhhhhh, two german guys taking a sauna. That’s my forehead slapping allocation done for the month!

Easy fix :smile:

1 Like

This is a great little intro to Varnish for the uninitiated.