Quantcast

plone.app.caching sets X-Cache-Rule of "plone.stableResource" for image from NamedBlobImage

classic Classic list List threaded Threaded
5 messages Options
khink khink
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

plone.app.caching sets X-Cache-Rule of "plone.stableResource" for image from NamedBlobImage

(The title might also have been "image uploaded in in image field stays
in browser cache after replacing".)

I have a "Member" type (dexterity) which has a "portrait" field [1] for
the profile picture (aka. avatar). We use this image in a "reflector" in
the login bar (and in different sizes in other places like profile
portlet and member listing).

After changing the avatar, the image url in the reflector [2] is unchanged.

All this happens on a Plone instance without anything in front, so no
Varnish. Plone.app.caching is installed. If i disable it, the new avatar
shows in the reflector immediately after saving.

Plone.app.caching sets an X-Cache-Rule "plone.stableResource" [3], but
that seems wrong here. I think "Content files and images" is more
appropriate, but can't find it in the caching controlpanel or the
p.a.caching docs [4]. How to change that? Maybe it already solves the
problem.

I've tried adding "@@images/portrait/profile" to the list of "Templates"
for "Content files and images" in the caching controlpanel, but i still
get the X-Cache-Rule:plone.stableResource header. I also added our
"member" type to the content types for "Content item view", to no avail.

Will changing the Cache rule help, and if so, how to do that? How else
can this be fixed?

Kees

[1] from interfaces.py:
     form.widget(portrait=NamedImageFieldWidget)
     portrait = namedfilefield.NamedBlobImage(
         title=_(u"portrait_form_label"),
         description=_(u"portrait_form_help"),
         required=False,
         constraint=check_image,
     )

[2] Our template code for reflector and profile portlets consciously
uses urls without the filename ('member_id/@@images/portrait/avatar',
'member_id/@@images/portrait/profile'). The browser decides it doesn't
need to get the newer version, therefore the user only sees the newer
image when the page is force-refreshed.

When the user goes to the form to change the image again, they do see
the correct image. This is because the image used there contains the
filename:
'member_id/@@edit/++widget++form.widgets.portrait/@@download/filename.jpg'
Obviously our templates (like the reflector) don't (want to) know about
filenames.

[3] headers (from Chromium developer):
Cache-Control:max-age=31536000, proxy-revalidate, public
Content-Length:2029
Content-Type:image/jpeg
Date:Thu, 12 Apr 2012 10:09:52 GMT
Expires:Fri, 12 Apr 2013 10:09:52 GMT
Last-Modified:Thu, 12 Apr 2012 10:09:46 GMT
Server:Zope/(2.13.12, python 2.6.7, linux2) ZServer/1.1
X-Cache-Operation:plone.app.caching.strongCaching
X-Cache-Rule:plone.stableResource

[4] http://pypi.python.org/pypi/plone.app.caching





------------------------------------------------------------------------------
For Developers, A Lot Can Happen In A Second.
Boundary is the first to Know...and Tell You.
Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
http://p.sf.net/sfu/Boundary-d2dvs2
_______________________________________________
Plone-Users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-users
khink khink
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: plone.app.caching sets X-Cache-Rule of "plone.stableResource" for image from NamedBlobImage

Update: In plone.app.caching, caching.zcml contains

     <!-- plone.namedfile downloadable -->
     <configure zcml:condition="installed plone.namedfile">

         <!-- These rely on the ContentItemLookup delegation -->
         <cache:ruleset ruleset="plone.content.file"
for="plone.namedfile.browser.Download" />
         <cache:ruleset ruleset="plone.stableResource"
for="plone.namedfile.scaling.ImageScale" />

     </configure>

Changing the value for "plone.namedfile.scaling.ImageScale" to
'plone.content.itemView' (for which "Moderate caching" is set) seems to
solve my problem.

Kees

On 04/12/2012 01:28 PM, Kees Hink wrote:

> (The title might also have been "image uploaded in in image field stays
> in browser cache after replacing".)
>
> I have a "Member" type (dexterity) which has a "portrait" field [1] for
> the profile picture (aka. avatar). We use this image in a "reflector" in
> the login bar (and in different sizes in other places like profile
> portlet and member listing).
>
> After changing the avatar, the image url in the reflector [2] is unchanged.
>
> All this happens on a Plone instance without anything in front, so no
> Varnish. Plone.app.caching is installed. If i disable it, the new avatar
> shows in the reflector immediately after saving.
>
> Plone.app.caching sets an X-Cache-Rule "plone.stableResource" [3], but
> that seems wrong here. I think "Content files and images" is more
> appropriate, but can't find it in the caching controlpanel or the
> p.a.caching docs [4]. How to change that? Maybe it already solves the
> problem.
>
> I've tried adding "@@images/portrait/profile" to the list of "Templates"
> for "Content files and images" in the caching controlpanel, but i still
> get the X-Cache-Rule:plone.stableResource header. I also added our
> "member" type to the content types for "Content item view", to no avail.
>
> Will changing the Cache rule help, and if so, how to do that? How else
> can this be fixed?
>
> Kees
>
> [1] from interfaces.py:
>       form.widget(portrait=NamedImageFieldWidget)
>       portrait = namedfilefield.NamedBlobImage(
>           title=_(u"portrait_form_label"),
>           description=_(u"portrait_form_help"),
>           required=False,
>           constraint=check_image,
>       )
>
> [2] Our template code for reflector and profile portlets consciously
> uses urls without the filename ('member_id/@@images/portrait/avatar',
> 'member_id/@@images/portrait/profile'). The browser decides it doesn't
> need to get the newer version, therefore the user only sees the newer
> image when the page is force-refreshed.
>
> When the user goes to the form to change the image again, they do see
> the correct image. This is because the image used there contains the
> filename:
> 'member_id/@@edit/++widget++form.widgets.portrait/@@download/filename.jpg'
> Obviously our templates (like the reflector) don't (want to) know about
> filenames.
>
> [3] headers (from Chromium developer):
> Cache-Control:max-age=31536000, proxy-revalidate, public
> Content-Length:2029
> Content-Type:image/jpeg
> Date:Thu, 12 Apr 2012 10:09:52 GMT
> Expires:Fri, 12 Apr 2013 10:09:52 GMT
> Last-Modified:Thu, 12 Apr 2012 10:09:46 GMT
> Server:Zope/(2.13.12, python 2.6.7, linux2) ZServer/1.1
> X-Cache-Operation:plone.app.caching.strongCaching
> X-Cache-Rule:plone.stableResource
>
> [4] http://pypi.python.org/pypi/plone.app.caching
>
>
>
>
>
> ------------------------------------------------------------------------------
> For Developers, A Lot Can Happen In A Second.
> Boundary is the first to Know...and Tell You.
> Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
> http://p.sf.net/sfu/Boundary-d2dvs2



------------------------------------------------------------------------------
For Developers, A Lot Can Happen In A Second.
Boundary is the first to Know...and Tell You.
Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
http://p.sf.net/sfu/Boundary-d2dvs2
_______________________________________________
Plone-Users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-users
David Glick (GW) David Glick (GW)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: plone.app.caching sets X-Cache-Rule of "plone.stableResource" for image from NamedBlobImage

In reply to this post by khink
On 4/12/12 4:28 AM, Kees Hink wrote:
(The title might also have been "image uploaded in in image field stays 
in browser cache after replacing".)

I have a "Member" type (dexterity) which has a "portrait" field [1] for 
the profile picture (aka. avatar). We use this image in a "reflector" in 
the login bar (and in different sizes in other places like profile 
portlet and member listing).

After changing the avatar, the image url in the reflector [2] is unchanged.

All this happens on a Plone instance without anything in front, so no 
Varnish. Plone.app.caching is installed. If i disable it, the new avatar 
shows in the reflector immediately after saving.

Plone.app.caching sets an X-Cache-Rule "plone.stableResource" [3], but 
that seems wrong here. I think "Content files and images" is more 
appropriate, but can't find it in the caching controlpanel or the 
p.a.caching docs [4]. How to change that? Maybe it already solves the 
problem.

I've tried adding "@@images/portrait/profile" to the list of "Templates" 
for "Content files and images" in the caching controlpanel, but i still 
get the X-Cache-Rule:plone.stableResource header. I also added our 
"member" type to the content types for "Content item view", to no avail.

Will changing the Cache rule help, and if so, how to do that? How else 
can this be fixed?

Kees

[1] from interfaces.py:
     form.widget(portrait=NamedImageFieldWidget)
     portrait = namedfilefield.NamedBlobImage(
         title=_(u"portrait_form_label"),
         description=_(u"portrait_form_help"),
         required=False,
         constraint=check_image,
     )

[2] Our template code for reflector and profile portlets consciously 
uses urls without the filename ('member_id/@@images/portrait/avatar', 
'member_id/@@images/portrait/profile'). The browser decides it doesn't 
need to get the newer version, therefore the user only sees the newer 
image when the page is force-refreshed.

When the user goes to the form to change the image again, they do see 
the correct image. This is because the image used there contains the 
filename: 
'[hidden email]' 
Obviously our templates (like the reflector) don't (want to) know about 
filenames.

[3] headers (from Chromium developer):
Cache-Control:max-age=31536000, proxy-revalidate, public
Content-Length:2029
Content-Type:image/jpeg
Date:Thu, 12 Apr 2012 10:09:52 GMT
Expires:Fri, 12 Apr 2013 10:09:52 GMT
Last-Modified:Thu, 12 Apr 2012 10:09:46 GMT
Server:Zope/(2.13.12, python 2.6.7, linux2) ZServer/1.1
X-Cache-Operation:plone.app.caching.strongCaching
X-Cache-Rule:plone.stableResource

[4] http://pypi.python.org/pypi/plone.app.caching

How are you generating your img tags for scales in templates? IIRC, inserting it via
<img tal:replace="structure context/@@images/portrait/profile" />
should generate URLs based on a hash of the image parameters, making it safe to cache aggressively because the URL changes when the image does. See the PyPI page for plone.app.imaging for other ways to generate the img tags with the hash-based URLs.

David

 

David Glick
Web Developer
[hidden email]
206.286.1235x32

GiveBIG is coming! Mark your calendar for May 2 and get ready to give big to Groundwire as part of this community-wide day of giving.



------------------------------------------------------------------------------
For Developers, A Lot Can Happen In A Second.
Boundary is the first to Know...and Tell You.
Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
http://p.sf.net/sfu/Boundary-d2dvs2
_______________________________________________
Plone-Users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-users
Laurence Rowe Laurence Rowe
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: plone.app.caching sets X-Cache-Rule of "plone.stableResource" for image from NamedBlobImage

David Glick (GW) wrote
On 4/12/12 4:28 AM, Kees Hink wrote:

(The title might also have been "image uploaded in in image field stays
in browser cache after replacing".)

I have a "Member" type (dexterity) which has a "portrait" field [1] for
the profile picture (aka. avatar). We use this image in a "reflector" in
the login bar (and in different sizes in other places like profile
portlet and member listing).

After changing the avatar, the image url in the reflector [2] is unchanged.

All this happens on a Plone instance without anything in front, so no
Varnish. Plone.app.caching is installed. If i disable it, the new avatar
shows in the reflector immediately after saving.

Plone.app.caching sets an X-Cache-Rule "plone.stableResource" [3], but
that seems wrong here. I think "Content files and images" is more
appropriate, but can't find it in the caching controlpanel or the
p.a.caching docs [4]. How to change that? Maybe it already solves the
problem.

I've tried adding "@@images/portrait/profile" to the list of "Templates"
for "Content files and images" in the caching controlpanel, but i still
get the X-Cache-Rule:plone.stableResource header. I also added our
"member" type to the content types for "Content item view", to no avail.

Will changing the Cache rule help, and if so, how to do that? How else
can this be fixed?

Kees

[1] from interfaces.py:
     form.widget(portrait=NamedImageFieldWidget)
     portrait = namedfilefield.NamedBlobImage(
         title=_(u"portrait_form_label"),
         description=_(u"portrait_form_help"),
         required=False,
         constraint=check_image,
     )

[2] Our template code for reflector and profile portlets consciously
uses urls without the filename ('member_id/@@images/portrait/avatar',
'member_id/@@images/portrait/profile'). The browser decides it doesn't
need to get the newer version, therefore the user only sees the newer
image when the page is force-refreshed.

When the user goes to the form to change the image again, they do see
the correct image. This is because the image used there contains the
filename:
'member_id/@@edit/++widget++form.widgets.portrait/@@download/filename.jpg<mailto:member_id/@@edit/++widget++form.widgets.portrait/@@download/filename.jpg>'
Obviously our templates (like the reflector) don't (want to) know about
filenames.

[3] headers (from Chromium developer):
Cache-Control:max-age=31536000, proxy-revalidate, public
Content-Length:2029
Content-Type:image/jpeg
Date:Thu, 12 Apr 2012 10:09:52 GMT
Expires:Fri, 12 Apr 2013 10:09:52 GMT
Last-Modified:Thu, 12 Apr 2012 10:09:46 GMT
Server:Zope/(2.13.12, python 2.6.7, linux2) ZServer/1.1
X-Cache-Operation:plone.app.caching.strongCaching
X-Cache-Rule:plone.stableResource

[4] http://pypi.python.org/pypi/plone.app.caching



How are you generating your img tags for scales in templates? IIRC, inserting it via




should generate URLs based on a hash of the image parameters, making it safe to cache aggressively because the URL changes when the image does. See the PyPI page for plone.app.imaging for other ways to generate the img tags with the hash-based URLs.
Hmm. This should probably be more robust and only cache as a stable resource when it is accessed with a unique name. Perhaps the plone.namedfile.scaling.ImageScale could be annotated with a IUniqueImageScale marker interface in __init__ when it is a unique url (i.e. if 'uid' in info) and have only that interface registered as a plone.stableResource.

Laurence
khink khink
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: plone.app.caching sets X-Cache-Rule of "plone.stableResource" for image from NamedBlobImage

In reply to this post by David Glick (GW)
Thanks David!

On 04/13/2012 11:06 PM, David Glick wrote:

> On 4/12/12 4:28 AM, Kees Hink wrote:
>> (The title might also have been "image uploaded in in image field stays
>> in browser cache after replacing".)
>>
>> I have a "Member" type (dexterity) which has a "portrait" field [1] for
>> the profile picture (aka. avatar). We use this image in a "reflector" in
>> the login bar (and in different sizes in other places like profile
>> portlet and member listing).
>>
>> After changing the avatar, the image url in the reflector [2] is unchanged.
>>
>> All this happens on a Plone instance without anything in front, so no
>> Varnish. Plone.app.caching is installed. If i disable it, the new avatar
>> shows in the reflector immediately after saving.
>>
>> Plone.app.caching sets an X-Cache-Rule "plone.stableResource" [3], but
>> that seems wrong here. I think "Content files and images" is more
>> appropriate, but can't find it in the caching controlpanel or the
>> p.a.caching docs [4]. How to change that? Maybe it already solves the
>> problem.
>>
>> I've tried adding "@@images/portrait/profile" to the list of "Templates"
>> for "Content files and images" in the caching controlpanel, but i still
>> get the X-Cache-Rule:plone.stableResource header. I also added our
>> "member" type to the content types for "Content item view", to no avail.
>>
>> Will changing the Cache rule help, and if so, how to do that? How else
>> can this be fixed?
>>
>> Kees
>>
>> [1] from interfaces.py:
>>       form.widget(portrait=NamedImageFieldWidget)
>>       portrait = namedfilefield.NamedBlobImage(
>>           title=_(u"portrait_form_label"),
>>           description=_(u"portrait_form_help"),
>>           required=False,
>>           constraint=check_image,
>>       )
>>
>> [2] Our template code for reflector and profile portlets consciously
>> uses urls without the filename ('member_id/@@images/portrait/avatar',
>> 'member_id/@@images/portrait/profile'). The browser decides it doesn't
>> need to get the newer version, therefore the user only sees the newer
>> image when the page is force-refreshed.
>>
>> When the user goes to the form to change the image again, they do see
>> the correct image. This is because the image used there contains the
>> filename:
>> 'member_id/@@edit/++widget++form.widgets.portrait/@@download/filename.jpg'
>> Obviously our templates (like the reflector) don't (want to) know about
>> filenames.
>>
>> [3] headers (from Chromium developer):
>> Cache-Control:max-age=31536000, proxy-revalidate, public
>> Content-Length:2029
>> Content-Type:image/jpeg
>> Date:Thu, 12 Apr 2012 10:09:52 GMT
>> Expires:Fri, 12 Apr 2013 10:09:52 GMT
>> Last-Modified:Thu, 12 Apr 2012 10:09:46 GMT
>> Server:Zope/(2.13.12, python 2.6.7, linux2) ZServer/1.1
>> X-Cache-Operation:plone.app.caching.strongCaching
>> X-Cache-Rule:plone.stableResource
>>
>> [4]http://pypi.python.org/pypi/plone.app.caching
>>
> How are you generating your img tags for scales in templates? IIRC,
> inserting it via
>
> <img tal:replace="structure context/@@images/portrait/profile" />
>
> should generate URLs based on a hash of the image parameters, making it
> safe to cache aggressively because the URL changes when the image does.
> See the PyPI page for plone.app.imaging for other ways to generate the
> img tags with the hash-based URLs.
>
> David
>
> *David Glick*
> Web Developer
> [hidden email]
> 206.286.1235x32
>
>
>
> GiveBIG is coming! Mark your calendar for May 2 and get ready to give
> big to Groundwire
> <http://www.seattlefoundation.org/npos/Pages/Groundwire.aspx> as part of
> this community-wide day of giving.
>
>
>
>
> ------------------------------------------------------------------------------
> For Developers, A Lot Can Happen In A Second.
> Boundary is the first to Know...and Tell You.
> Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
> http://p.sf.net/sfu/Boundary-d2dvs2
>
>
>
> _______________________________________________
> Plone-Users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/plone-users



------------------------------------------------------------------------------
For Developers, A Lot Can Happen In A Second.
Boundary is the first to Know...and Tell You.
Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
http://p.sf.net/sfu/Boundary-d2dvs2
_______________________________________________
Plone-Users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-users
Loading...