How to invalidate cached items in ZXTM's Content Cache

When several client request the same web page, ZXTM does not have to query the back-end origin server every time. Instead, you can use ZXTM's content caching capability to remember common web page responses; this reduces the load on your origin servers, improves total ZXTM throughput and ensures that clients receive web pages more quickly.

Web page responses are cached for 10 minutes, which is a sensible value if the page does not change often. In some circumstances, you may want to remove a page (or set of pages) from ZXTM's cache, for example, if you've just updated the content. This article describes a range of techniques to do this.

Introduction

There is a good overview of how ZXTM's content caching works in the Making the Most of Content Caching article, and you can also refer to the Content Caching documentation in the ZXTM User Manual.

This article describes a number of different ways to manage the expiration of items in the content cache:

  1. Fine-grained Cache Control
  2. Resetting the Content Cache
  3. Invalidating items with HTTP requests
  4. Full control with TrafficScript


Fine-grained Cache Control

The default cache time of 10 minutes is probably sufficient for the large majority of cachable content. You can change the cache time to a different value by editing the Content Caching settings of the Virtual Server.

You may want to specify different cache times for different types of content. For example, the vast majority of your content may be cachable for 10 minutes, but some pages should only be cached for 5 seconds.

ZXTM conforms accurately with the Cache recommendations of RFC 2616 (section 14.9), so you can control its behaviour by modifying request and response headers as appropriate.

The following TrafficScript response rule will set the cache time for certain URLs to 5 seconds:

$url = http.getPath();

if( $url == "/news.cgi" || $url == "/headlines.cgi" ) {
   http.addResponseHeader( "Cache-Control", "max-age=5" );
}


Resetting the Content Cache

You can completely clear ZXTM's content cache using the Administration Server, or remotely via the ZXTM Control API.

In the Administration Server, go to the Activity > Content Cache page and use the Clear Content Cache button to clear the content cache on all ZXTMs in your cluster.

With the ZXTM Control API, use the System.Cache.clearWebCache() SOAP method to clear the content cache on the local ZXTM. The code sample 'Clearing ZXTM's Content Cache' describes how to do this using Perl; other languages are also supported.

Ways to invalidate cached items


Remote HTTP requests

If you want ZXTM to invalidate its cache of a particular item, add the following HTTP header to a request for the item:

Cache-Control: no-cache

ZXTM will bypass its cached version of the resource and retrieve a new version from the origin server. This new version will normally be cached, so subsequent requests will receive the new version from ZXTM's cache.

You can manually issue such a request using the 'httpclient' command-line application included with ZXTM, in ZEUSHOME/admin/bin:

httpclient -H "Cache-Control: no-cache" http://host/news.aspx

Run 'httpclient -h' for documentation.

Using 'shift-reload' in Firefox or 'control-F5' in MSIE also causes these browers to add the 'no-cache' header to the request, and invalidates the cache for all users.

Note that this technique will not work reliably on multi-processor systems - see the note at the end of this article.


TrafficScript control

The following TrafficScript rule reads a list of URLs from a resource file, and invalidates each URL:

# Has the list of URLs to refresh been updated?
$lastupdate = data.get( "lastupdate" );

log.info( "Last update = " . $lastupdate );
if( resource.getMTime( "refreshurls" ) > $lastupdate ) {
   # Add the new urls to our table
   $list = resource.get( "refreshurls" );
   while( string.regexmatch( $list, "(.*?)\\\n(.*)" ) ) {
      log.info( "Need to invalidate URL ".$1 );
      data.set( $1, 1 );
      $list = $2;
   }
   data.set( "lastupdate", resource.getMTime( "refreshurls" ) );
}

$url = http.getPath();
log.info( $url );
if( data.get( $url ) ) {
   http.addHeader( "Cache-Control", "no-cache" );
   log.info( "Invalidating URL ".$url );
   data.set( $url, 0 );
}

You will need to put the list of urls in a file named 'refreshurls', in the ZEUSHOME/zxtm/conf/extra directory:

/news.cgi
/headlines.cgi
/private/admin.aspx

When you update the file, ZXTM will notice that it has changed and reload it. When the TrafficScript rule runs, it will detect that the file has changed, update the internal table of URLs and invalidate all URLs in the table when corresponding requests are recieved.

The impact of this is minimal. ZXTM caches the file contents and modification times, and the TrafficScript rule will have a very minor effect on the performance of the system.

You can remotely control the list of URLs using the Control API Conf.Extra.addFile() and getFile() functions, or simply by scp'ing the list to the correct location on the ZXTM systems. Each time the file is updated, all of the URLs listed in it will be invalidated when a corresponding request is received.

Owen Garrett [Zeus Dev Team] 19 September 2006  Permalink  
Leave a comment ...
Your email address will not be displayed.
Your URL will be displayed.
This public messageboard is not a forum for technical support. To report technical support problems, please contact our dedicated Support team using the instructions at the bottom of this page.
Options:
 
(Line breaks become <br />)
(Set cookies for name, email & url)
Download Free ZXTM Desktop Edition

Recent Articles

Other Resources



www.zeus.com