Warning

This document hasn't been checked for compatibility with current versions of Plone. Use at your own risk.

Cache Content- Anonymous only

by rnunez last modified Dec 06, 2009 09:27 PM
How to change Plone's default cache settings so you can cache pages on your site.(Anonymous only)

go to the ZMI portal_skins/plone_templates/global_cache_settings, click customize.

change the content to:

<metal:cacheheaders define-macro="cacheheaders">
<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,Cookie,Accept-Encoding')" />
<metal:block tal:define="dummy python:request.RESPONSE.setHeader('Last-Modified', here.modified().toZone('GMT').rfc822())" />
<metal:block tal:content="structure python:here.enableHTTPCompression(request=request, debug=0)" />
<tal:block condition="isAnon">
<metal:block tal:define="dummy python:request.RESPONSE.setHeader('Cache-control','max-age=3600,s-maxage=3600')" />
</tal:block>
<tal:block condition="not:isAnon">
<metal:block tal:define="dummy python:request.RESPONSE.setHeader('Cache-control','Must-revalidate,max-age=0,no-cache')" />
<metal:block tal:define="dummy python:request.RESPONSE.setHeader('Pragma','no-cache')" />
</tal:block>
</metal:cacheheaders>

all content will be cache for a hour for anonymous user

if you want to extend the time you can use apache, I enabled the expires_module (on the non-ssl conection only):

LoadModule expires_module modules/mod_expires.so

and set the virtualhost as follow:

ExpiresActive On
ExpiresDefault "access plus 1 hour"
ExpiresByType image/gif "access plus 1 week"
ExpiresByType image/jpeg "access plus 1 week"
ExpiresByType text/css "access plus 1 day"
ExpiresByType application/x-javascript "access plus 1 week"

Gotchas

If I went to http://hostname/ and saw a cached page and then logged in and went to http://hostname/ - I would be logged in but would still see a cached page, or it would kill the cache and the next anonymous visit would not get a cached page. This should be used in conjunction with separate host names:

  • http://hostname/ for cached/anonymous content
  • http://adminhostname/ for non-anonymous users

You also will want to change portal_caching_manager


Contribute

Something wrong or out of date? Anybody can edit or create a new article in the knowledge base. Simply create an account on this site, log in, and click the Edit button to contribute.