image caching

1 view
Skip to first unread message

Lea H

unread,
Nov 25, 2009, 3:29:03 AM11/25/09
to pylons-discuss
Hi,
I have an image like that <img src='controller/action' /> that calls
action in controller. This action creates a PIL and sends it to the
browser. It seems that once the action was called the resulting image
is cached and reused every time the image is shown (the action is not
called anymore). Since the image contains dynamic data I need it to be
re-created every time I go on that page. Can I somehow tell the
browser not to cache that specific image?

Thanks for you help.

Cheers,
Lea

Stephen Emslie

unread,
Nov 25, 2009, 10:49:00 AM11/25/09
to pylons-...@googlegroups.com
How about adding a unique query string to the request? e.g.

<img src="/controller/action?<timestamp>"/>



--

You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To post to this group, send email to pylons-...@googlegroups.com.
To unsubscribe from this group, send email to pylons-discus...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.



Lea Hänsenberger

unread,
Nov 25, 2009, 11:00:12 AM11/25/09
to pylons-...@googlegroups.com
That's simple ;-). Thank you.

Alexandre Conrad

unread,
Nov 25, 2009, 11:17:53 AM11/25/09
to pylons-...@googlegroups.com
Hi,

I don't know the answer as I haven't really used caching, but I guess
the correct way to do it is to play with the HTTP headers, tweaking
the Cache-Control setting.

The headers can be changed with the response object, available in your
controller:

# Set HTTP response headers before returning
response.headers['Cache-Control'] = 'some value here'

Here's the RFC about Cache-Control:

http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9

Regards,
Alex

2009/11/25 Lea H <baer...@gmail.com>:

vince spicer

unread,
Nov 25, 2009, 9:22:02 AM11/25/09
to pylons-...@googlegroups.com
--

You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To post to this group, send email to pylons-...@googlegroups.com.
To unsubscribe from this group, send email to pylons-discus...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.




Lea,

There are a few things you can do to disable caching, the oldest way is to append a timestamp into the url so the image url is different on every request.

EX: 

"""<img src="/controller/image?time=%s">""" % time.time()
then in your controller ensure you except the time argument

or you can use cache-control/max-age headers on the returning image, to tell the browser to refresh.  However this does tend to be browser specific and can be fun finding the right headers to return for all browsers.

Hope this helps,

Vince
Reply all
Reply to author
Forward
0 new messages