Disabling caching on single browserview

Hi,

I've been trying to find docs on this but I can't find a way to disable caching on a individual browserview. How can I disable all caching on a single browserview? Does there exist a decorator like how you cache memoize but opposite?

Here is the walk through of my issue:

  • User lands on browserview.
  • It checks if they are proxied through our secure server?
  • If no, redirect them to the proxy login.
  • After logging in, it redirects them back to the browserview they were trying to access.
  • Endless loop happens back and forth.

Looking at the network, it appears the web browser remember the original page was a 302 redirect and just executes it again. I'm 99% sure it is the cache because you can clear the cache and then land on the page with no problem.

We are using Plone 5 and Varnish 4. We need heavy caching on our site because it has 90,000 dexterity objects.

Thanks,
David

Option 1 (quick and dirty):

Set the Cache-control header directly in your view code:

request.response.setHeader('Cache-Control', 'no-cache, no-store')

Option 2 (more centralized and configurable):

Add a new cache ruleset:

<configure xmlns:cache="http://namespaces.zope.org/cache">
    <cache:rulesetType
        name="plone.transient"
        title="Transient views"
        description="Should not be cached"
        />
</configure>

Associate it with your view:

<cache:ruleset ruleset="plone.transient" for=".path.to.MyView" />

Now you can use the caching control panel to assign the "no caching" operation to this ruleset (Or do that using registry.xml in your GenericSetup profile).

2 Likes

Thanks David.

I tried both but it is always overridden. I think is the dexterity type this browserview is on has ModerateCaching set and is overriding it. I can confirm it in the network and when I switch "Content Items" to no-caching everything works.

Is there a way to have one dexterity type cache differently? I don't want to turn no-caching on Content Items in the caching panel because that will have major impacts.

maybe you can tweak your Varnish configuration to override the HTTP Cache-Control header on your specific view.

@davisagli would be a nice addition to https://docs.plone.org/manage/deploying/caching/caching.html#setting-per-view-cache-rules.

I can't find plone.transient in https://github.com/plone/plone.app.caching/blob/4b7fa0e0f953c89efcff21aeeb0b9f3497121889/plone/app/caching/caching.zcml#L38. Do you know exactly where this comes from?

It doesn't come from anywhere; it's a new ruleset defined by the zcml I gave you.

Re-reading this I realized how stupid the question was. Thanks for being polite :laughing: