I'm trying to make a quick and dirty random image product. It is a zClass based off of OFS::Folder. The index_html method is as follows: context.REQUEST.RESPONSE.setHeader( 'Cache-Control' ,'no-cache' ) context.REQUEST.RESPONSE.setHeader( 'Pragma' ,'no-cache' ) image_set = [] images = context.objectValues('Image') for each in images: image_set.append(each) return_image = image_set[random.choice(range(0,len(image_set)))] return return_image.index_html(context.REQUEST,context.REQUEST.RESPONSE) This works fine as long as one shift-reloads the image. Otherwise it does not change the image. Obviously my attempts to defeat the browser cache are not succeeding. Can anyone tell me why?
From: "Edward Pollard" <pollej@uleth.ca>
I'm trying to make a quick and dirty random image product.
It is a zClass based off of OFS::Folder.
The index_html method is as follows: context.REQUEST.RESPONSE.setHeader( 'Cache-Control' ,'no-cache' ) context.REQUEST.RESPONSE.setHeader( 'Pragma' ,'no-cache' )
image_set = [] images = context.objectValues('Image')
for each in images: image_set.append(each)
return_image = image_set[random.choice(range(0,len(image_set)))] return return_image.index_html(context.REQUEST,context.REQUEST.RESPONSE)
This works fine as long as one shift-reloads the image. Otherwise it does not change the image. Obviously my attempts to defeat the browser cache are not succeeding.
Try adding setting the expiry time: <meta http-equiv="expires" content="Sat, 01 Jan 2001 00:00:00 GMT"> HTH Jonathan
On Apr 28, 2004, at 12:22 PM, Small Business Services wrote:
Try adding setting the expiry time:
<meta http-equiv="expires" content="Sat, 01 Jan 2001 00:00:00 GMT">
Of course, I'm dealing with images, not HTML content, so META tags are right out. But I added this as a header (using the same mechanism as the previous example) with no luck. I guess I'm drifting into the HTTP standard for requesting images, which is a bit outside the scope of this list. Perhaps my logs will be helpful in discerning what my browser thinks its doing. If anyone has any other insight I'd sure appreciate it. --- Edward J. Pollard, B.Sc Webmaster, University of Lethbridge
Edward Pollard wrote:
On Apr 28, 2004, at 12:22 PM, Small Business Services wrote:
Try adding setting the expiry time:
<meta http-equiv="expires" content="Sat, 01 Jan 2001 00:00:00 GMT">
Of course, I'm dealing with images, not HTML content, so META tags are right out.
But I added this as a header (using the same mechanism as the previous example) with no luck.
I've had some luck with this combination: RESPONSE.setHeader('Expires', 'Fri, 05 Jul 2002, 05:00:00 GMT' ); RESPONSE.setHeader('Cache-Control', 'no-store'); RESPONSE.setHeader('Pragma', 'no-cache'); I think the only difference from what you've tried is setting 'Cache-Control' to 'no-store' instead of 'no-cache'. Mark _____
Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
On Apr 28, 2004, at 2:53 PM, Mark Gibson wrote:
Edward Pollard wrote:
On Apr 28, 2004, at 12:22 PM, Small Business Services wrote:
Try adding setting the expiry time:
<meta http-equiv="expires" content="Sat, 01 Jan 2001 00:00:00 GMT">
Of course, I'm dealing with images, not HTML content, so META tags are right out. But I added this as a header (using the same mechanism as the previous example) with no luck.
I've had some luck with this combination:
RESPONSE.setHeader('Expires', 'Fri, 05 Jul 2002, 05:00:00 GMT' ); RESPONSE.setHeader('Cache-Control', 'no-store'); RESPONSE.setHeader('Pragma', 'no-cache');
No improvement. It is noted that when I hold shift-reload, I keep getting different images (as discussed previously). When I don't hold shift, I get the same image over and over. However, it is ALWAYS the first image in the list (alphabetically). Weird. Maybe my code has something wrong with it. --- Edward J. Pollard, B.Sc Webmaster, UnivERS
Edward Pollard wrote:
On Apr 28, 2004, at 2:53 PM, Mark Gibson wrote:
Edward Pollard wrote:
On Apr 28, 2004, at 12:22 PM, Small Business Services wrote:
Try adding setting the expiry time:
<meta http-equiv="expires" content="Sat, 01 Jan 2001 00:00:00 GMT">
Of course, I'm dealing with images, not HTML content, so META tags are right out. But I added this as a header (using the same mechanism as the previous example) with no luck.
I've had some luck with this combination:
RESPONSE.setHeader('Expires', 'Fri, 05 Jul 2002, 05:00:00 GMT' ); RESPONSE.setHeader('Cache-Control', 'no-store'); RESPONSE.setHeader('Pragma', 'no-cache');
No improvement.
Hmm. You said this was the index_html in a Zclass. Can you have it return an <img> tag instead of the image itself? Then you could do something like this: imageid=randomImage() #returns id of some random image return '<img src="%s/%s" />'%(context.absolute_url(),imageid) No more caching issues. Mark
participants (3)
-
Edward Pollard -
Mark Gibson -
Small Business Services