How to invalidate cached items in ZXTM's Content CacheWhen 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. IntroductionThere 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:
Fine-grained Cache ControlThe 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 CacheYou 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 Ways to invalidate cached itemsRemote HTTP requestsIf 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 httpclient -H "Cache-Control: no-cache" http://host/news.aspx
Run ' Using 'shift-reload' in Firefox or 'control-F5' in MSIE also causes these browers to add the ' Note that this technique will not work reliably on multi-processor systems - see the note at the end of this article. TrafficScript controlThe 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 /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
Owen Garrett
[Zeus Dev Team] 19 September 2006
|
Recent Articles
Other Resources
|


