Customize cache for specific behavior of a view

We are trying to customize the cache header of a response.
We have a cache rule for a view, but in a specific situation we want to be able to intercept the request and change the cache type to a different one.

We had a look at the plone.caching documentation and we were able to define a custom cache rule, create an operation and map it to the view.
This way we could indeed alter the response header with the customized cache parameters.
However, we still want this view to have the other default type of caching generally. We just want the custom rule for a specific subset of the view.

We were thinking of two ways.
Maybe we can create a different class that inherits the other view, so that we can map the custom rule only to this new view?
Or the other way would be to change the request on the traverser, so that plone.caching then somehow knows that this request needs to be treated differently.

Do you have any ideas? What path would you suggest?

We are using Plone 5.

Thank you!

1 Like

I think this is the more idiomatic approach.

If you choose the other approach you may add a marker interface to the published view object and then map a caching rule to this marker interface.


Thank you very much! It worked!

1 Like