Cache Content
This How-to applies to:
Plone 2.1.x, Plone 2.0.x
This How-to is intended for:
Server Administrators
Caching Overview
Andy McKay gave an excellent presentation on this topic at the first Plone conference. Read his presentation notes
Some other resources worth reading:
- http://doc.lld.dk/wiki/CachingWithApache
- http://his.biologie.hu-berlin.de/PloneBook/ch14.rst
- http://zopewiki.org/ScalingZope
- http://www.vasudevaservice.com/documentation/articles/plone_speed
Plone Modifications
Plone's default cache settings do not cache pages. Use the following information to change the settings and let your site cache pages. You need to modify the global_cache_settings file in the plone_templates directory:
<metal:block tal:define="dummy python:request.RESPONSE.setHeader('Content-Type','text/html;;charset=%s' % charset)" />
<metal:block tal:define="dummy python:request.RESPONSE.setHeader('Content-Language', lang)" />
<metal:block tal:define="dummy python:request.RESPONSE.setHeader('Vary', 'Accept-Language,Accept-Encoding,User-Agent,Cookie')" />
<metal:block tal:define="dummy python:request.RESPONSE.setHeader('Pragma', 'no-cache')" />
<metal:block tal:define="dummy python:request.RESPONSE.setHeader('Connection', 'keep-alive')" />
<metal:block tal:define="dummy python:request.RESPONSE.setHeader('Last-Modified', 'here.modified().toZone('GMT').rfc822())" />
Explanation of code above
- Vary setting
- tells upstream caches to cache by language, encoding, browser and cookie. Note that Internet Explorer requires a page in different languages to have a distinct url for each language, even when language value is different here.
- Pragma : no-cache setting
- tells browsers to not cache the content. The content should be cached only by Apache, Squid or some other cache on the server, for optimal cache control.
- Connection : keep-alive setting
- allows persistent connections which can speedup latency times for HTML documents with lots of images.
- LastModified header
- reports the actual last modified time of the object to an upstream cache, which makes sense for caching.
Zope Modifications
If you are going to use one or more HTTP Accelerated Cache Managers, you need to fix a bug in Zope's AcceleratedHTTPCacheManager.py file. Uncomment the following line:
RESPONSE.setHeader('Last-Modified',rfc1123_date(time.time()))
This will ensure that Zope returns a valid Last-Modified HTTP header. Without it, caches will assume that your content has been dynamically generated and is not suitable for caching.
Suggested global_cache_settings broke Content_Type encoding in Firefox/Mozilla and Safari
Those who copied the global_cache_settings from an earlier version of this document ended up with broken Content-Type header settings for Mozilla/Firefox and Safari users. The Content-Type was set to charset = %s. The spaces around the = are no problem for IE(6), but destroys utf-8 characterson these other browsers, like ä, î, é and friends.
Changed in the document.
This how-to breaks Plone
If you follow these instructions in Plone 2.1.2, it will break your plone instance. I would not do what this document reccommends. Now to reinstall...
stray apostrophe
This should work. You will have to make sure all your servers are set to use GMT. I also don't understand why the no-cache and keep-alive headers are included. I think it would be best to remove those lines, although I have left them in the code below. The Zope bug this article talks about has been fixed in the distribution that came with Plone 2.1.2 for SuSE Linux (2.7 ?).
How do I post code examples?
Plone.org didn't like my code example. Remove the apastrophe in front of here.modified in the last line of code.
It breaks localized user interface
I dont recommend using this for websites where localized user interface is used. It took me two weeks to find out where that fuc**ng problem was.
doc sprint review
Consider revising so that this how to is more procedural. Use numbers to indicate each step. This how to also seems to assume some prerequisite knowledge. Is that what the external links are for? If so, please indicate that the user should read (and know?) X,Y, and Z first before completing this procedure.