Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I guess the real answer here is probably that there's no easy way to do this at the moment. I've raised a <a href="http://dev.plone.org/plone/ticket/11990" rel="nofollow">Plone bug to allow max-age to be overriden with moderateCaching</a></p> <p>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:</p> <pre class="lang-python prettyprint-override"><code>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 </code></pre> <p>Register this in configure.zcml</p> <pre class="lang-xml prettyprint-override"><code>&lt;adapter factory=".operation.CacheInApache" name="cacheInApache" /&gt; &lt;utility component=".operation.CacheInApache" name="cacheInApache" /&gt; </code></pre> <p>Then in my generic setup profile registry.xml I configure my types to use it and define its fields.</p> <pre class="lang-xml prettyprint-override"><code>&lt;record name="plone.caching.interfaces.ICacheSettings.operationMapping"&gt; &lt;value purge="False"&gt; &lt;element key="plone.resource"&gt;plone.app.caching.strongCaching&lt;/element&gt; &lt;element key="plone.stableResource"&gt;plone.app.caching.strongCaching&lt;/element&gt; &lt;element key="plone.content.itemView"&gt;cacheInApache&lt;/element&gt; &lt;element key="plone.content.feed"&gt;cacheInApache&lt;/element&gt; &lt;element key="plone.content.folderView"&gt;cacheInApache&lt;/element&gt; &lt;element key="plone.content.file"&gt;cacheInApache&lt;/element&gt; &lt;/value&gt; &lt;/record&gt; &lt;record name="cacheInApache.smaxage"&gt; &lt;field type="plone.registry.field.Int"&gt; &lt;title&gt;Shared maximum age&lt;/title&gt; &lt;description&gt;Time (in seconds) to cache the response in the caching proxy&lt;/description&gt; &lt;required&gt;False&lt;/required&gt; &lt;/field&gt; &lt;value&gt;86400&lt;/value&gt; &lt;/record&gt; &lt;record name="cacheInApache.etags"&gt; &lt;field type="plone.registry.field.Tuple"&gt; &lt;title&gt;ETags&lt;/title&gt; &lt;description&gt;A list of ETag component names to include&lt;/description&gt; &lt;value_type type="plone.registry.field.ASCIILine" /&gt; &lt;required&gt;False&lt;/required&gt; &lt;/field&gt; &lt;value&gt; &lt;/value&gt; &lt;/record&gt; &lt;record name="cacheInApache.lastModified"&gt; &lt;field type="plone.registry.field.Bool"&gt; &lt;title&gt;Last-modified validation&lt;/title&gt; &lt;description&gt;Turn on Last-Modified headers&lt;/description&gt; &lt;required&gt;False&lt;/required&gt; &lt;/field&gt; &lt;value&gt;False&lt;/value&gt; &lt;/record&gt; &lt;record name="cacheInApache.ramCache"&gt; &lt;field type="plone.registry.field.Bool"&gt; &lt;title&gt;RAM cache&lt;/title&gt; &lt;description&gt;Turn on caching in Zope memory&lt;/description&gt; &lt;required&gt;False&lt;/required&gt; &lt;/field&gt; &lt;value&gt;False&lt;/value&gt; &lt;/record&gt; &lt;record name="cacheInApache.vary"&gt; &lt;field type="plone.registry.field.ASCIILine"&gt; &lt;title&gt;Vary&lt;/title&gt; &lt;description&gt;Name(s) of HTTP headers that must match for the caching proxy to return a cached response&lt;/description&gt; &lt;required&gt;False&lt;/required&gt; &lt;/field&gt; &lt;value&gt;&lt;/value&gt; &lt;/record&gt; &lt;record name="cacheInApache.anonOnly"&gt; &lt;field type="plone.registry.field.Bool"&gt; &lt;title&gt;Only cache for anonymous users&lt;/title&gt; &lt;description&gt;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.&lt;/description&gt; &lt;required&gt;False&lt;/required&gt; &lt;/field&gt; &lt;value&gt;False&lt;/value&gt; &lt;/record&gt; </code></pre> <p>You can also define some type specific overrides.</p> <p>If anyone can suggest a simpler way to achieve this then please let me know </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload