I guess the real answer here is probably that there's no easy way to do this at the moment. I've raised a Plone bug to allow max-age to be overriden with moderateCaching
So here's my solution, that works, but seems a lot of work compared to being able to override the default max age on moderate caching. I define my own caching operation, that extends plone.app.caching.operations.default.moderateCaching:
class CacheInApache(ModerateCaching):
""" Apache won't cache a response if max-age cache control is 0. Override ModerateCaching
and set it to 1 second.
"""
classProvides(ICachingOperationType)
title = _(u"Cache in Apache")
description = _(u"Moderate caching for Plone behind Apache. max-age set to 1")
prefix = 'cacheInApache'
maxage = 1
Register this in configure.zcml
<adapter factory=".operation.CacheInApache"
name="cacheInApache" />
<utility component=".operation.CacheInApache"
name="cacheInApache" />
Then in my generic setup profile registry.xml I configure my types to use it and define its fields.
<record name="plone.caching.interfaces.ICacheSettings.operationMapping">
<value purge="False">
<element key="plone.resource">plone.app.caching.strongCaching</element>
<element key="plone.stableResource">plone.app.caching.strongCaching</element>
<element key="plone.content.itemView">cacheInApache</element>
<element key="plone.content.feed">cacheInApache</element>
<element key="plone.content.folderView">cacheInApache</element>
<element key="plone.content.file">cacheInApache</element>
</value>
</record>
<record name="cacheInApache.smaxage">
<field type="plone.registry.field.Int">
<title>Shared maximum age</title>
<description>Time (in seconds) to cache the response in the caching proxy</description>
<required>False</required>
</field>
<value>86400</value>
</record>
<record name="cacheInApache.etags">
<field type="plone.registry.field.Tuple">
<title>ETags</title>
<description>A list of ETag component names to include</description>
<value_type type="plone.registry.field.ASCIILine" />
<required>False</required>
</field>
<value>
</value>
</record>
<record name="cacheInApache.lastModified">
<field type="plone.registry.field.Bool">
<title>Last-modified validation</title>
<description>Turn on Last-Modified headers</description>
<required>False</required>
</field>
<value>False</value>
</record>
<record name="cacheInApache.ramCache">
<field type="plone.registry.field.Bool">
<title>RAM cache</title>
<description>Turn on caching in Zope memory</description>
<required>False</required>
</field>
<value>False</value>
</record>
<record name="cacheInApache.vary">
<field type="plone.registry.field.ASCIILine">
<title>Vary</title>
<description>Name(s) of HTTP headers that must match for the caching proxy to return a cached response</description>
<required>False</required>
</field>
<value></value>
</record>
<record name="cacheInApache.anonOnly">
<field type="plone.registry.field.Bool">
<title>Only cache for anonymous users</title>
<description>Ensure logging users always get a fresh page. Note that if you are caching pages in a proxy cache, you'll still need to use a Vary response header to keep anonymous and authenticated content separate.</description>
<required>False</required>
</field>
<value>False</value>
</record>
You can also define some type specific overrides.
If anyone can suggest a simpler way to achieve this then please let me know