Updating attached image of news item does not purge scaled image from varnish but only the news item view

StackOverflow https://stackoverflow.com/questions/20588907

Question

Whenever a user replaces/updates the image attached to a news item, then the news item view and folder listing above is purged (updated) on the varnish cache – but the attached image itself is not.

How can I make plone.app.caching to also purge/update not only <mysite>/news/ and <mysite>/news/news-item/ but also the images under <mysite>/news/news-item/image_news_scale and <mysite>/news/news-item/image_even_smaller_news_scale?

Background: Using Plone 4.3.2 I setup my a own custom image scales, e.g. news_scale via <mysite>/@@imaging-controlpanel. This scale is used for displaying the attached images in news items, e.g. as <mysite>/news/news-item/image_news_scale. Moreover, I also have another custom image scale like even_smaller_news_scale to be used in folder listings, e.g. as <mysite>/news/news-item/image_even_smaller_news_scale. I created these views via <mysite>/portal_skins/custom and registered them as default views under <mysite>/portal_types/ and select_default_view action.

PS I just saw now, because I am using raptus.multilanguageplone, the images' URL are available even under a more complicated URL that is dependent upon selected language: <mysite>/news/news-item/image___de____news_scale and <mysite>/news/news-item/image___de____even_smaller_news_scale (de could also be en depending on language)

Was it helpful?

Solution

if you already configured cache purging in plone.app.caching correctly you'll notice that newsitem/image_thumb and other image sizes will get purged correctly by default.

plone.app.caching does not know about the custom urls for the images because of raptus.linguaplone. so you'll have to create your own adapter that implements IPurgePaths for your newsitems

something like this should do the trick:

from z3c.caching.interfaces import IPurgePaths


class ItemImagePurgePaths(object):
    """additional paths to purge not covered by 
    plone.app.caching default adapters i.e. ObjectFieldPurgePaths
    """
    implements(IPurgePaths)
    adapts(IYourConentType)

    def __init__(self, context):
        self.context = context

    def getRelativePaths(self):
        prefix = self.context.absolute_url_path()

        return [prefix + '/image____de____news_scale',
                prefix + '/image____de____even_smaller_scale']

    def getAbsolutePaths(self):
        return []    

see also https://pypi.python.org/pypi/plone.cachepurging

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top