Re: Preventing an image from caching
by merlyn (Sage) on Nov 28, 2000 at 03:36 UTC
|
The RFC'ed way to stop an image from caching is to "ship it expired". Set the
Last-Modified header to now, and expires also to now, as a proper HTTP date,
of course.
-- Randal L. Schwartz, Perl hacker | [reply] |
|
Thanks Randal. What is the proper syntax for the above, I can't seem to find it. Would I generate the date:time within the CGI and then use a variable to place the current date and time into the header? Is there a specific syntax that the date has to be in?
| [reply] |
|
With CGI.pm, you can use the -expires switch to the header routine. Apparently, CGI::Util also has an expires
routine that you can use to calculate the proper format. If you don't like digging
around in the innards of CGI.pm, pull up HTTP::Date, which formats things
according to the RFC. Something like this:
use HTTP::Date qw(time2str);
my $now = time2str(time);
print "Expires: $now\nLast-modified: $now\n";
# add other headers here
-- Randal L. Schwartz, Perl hacker | [reply] [d/l] |
|
Re: Preventing an image from caching
by cleen (Pilgrim) on Nov 28, 2000 at 03:59 UTC
|
Well if your talking about caching with proxy servers (IE Squid), by default squid and such cache's wont cache dynamic content, ie *.cgi? or *.pl? *.shtml ,or set the last updated to the current time in the headers.
| [reply] |
Re: Preventing an image from caching
by bastard (Hermit) on Nov 28, 2000 at 20:19 UTC
|
If you are generating the page, append a random number to the call for the image.
<IMG SRC="/cgi-bin/image.pl?rand=4531269823">
Each time the page draws the string will be different, eliminating the cached image problem because to the browser it is not the same image. | [reply] [d/l] |
|
Thanks for the post, but I am generating the image, saving it to a file, then calling the file with the <IMG...> tag. I can't seem to get the image to go directly to the page because all I get is ASCII text instead of hte binary.
| [reply] |
|
Call the file with this script.
#!/bin/perl
$image = `cat imagenameandpath`;
print "Content-type: image/png\n\n";
print $image;
It's the simplest way i know.
BTW- image/png is for png file format, substitute gif, jpeg, for others. | [reply] [d/l] |
Re: Preventing an image from caching
by lemming (Priest) on Nov 29, 2000 at 01:51 UTC
|
This website talks about the cache fairly clearly and shows various details on controlling the cache for different objects.
Cache info at netapp.com | [reply] |
Re: Preventing an image from caching
by extremely (Priest) on Nov 28, 2000 at 04:51 UTC
|
| [reply] |
Re: Preventing an image from caching
by belize (Deacon) on Nov 28, 2000 at 17:41 UTC
|
I need to make another condition here. I do not want to stop the other images on the page to not cache as they include navigation bars and other images that appear on every page. If the entire page has to be reloaded everytime, then the whole program slows down by a factor of 50. I only need the image that is generated by GD on the fly to not cache.
All the solutions so far I believe are applied to the entire page (all images) and not only to the generated image.
I hope I am clear and not missing something easy.
Tony | [reply] |