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.