in reply to Trouble Caching an Image

A couple of suggestions:

First, use strict; at the top of the module will keep you out of a lot of trouble.

Next, use CGI; and using it to parse URLs and forms will keep you out of even more trouble. "As simple as possible" is not a good argument. The code you provided would be shorter if you used CGI. (If you're worried about performance, consider CGI::Lite.) In this case, never mind.

Next, if you're running a current (or nearly current) Perl distribution, the date manipulation routines you need should be included, saving you the trouble of lugging around custom methods of uncertain ancestry.

Try something like the following fragment:

use HTTP::Date qw(time2str); my $now = time2str($filetime); my $expires = time2str($filetime + $delta); print "Last-modified: $now\n"; print "Expires: $expires\n";
Finally, one of the subtle problems you'll have is that getting expire times to work depends on a couple of things that might be out of your control.

Treat setting the Expires header as an optimization, and be prepared to have it ignored.

Replies are listed 'Best First'.
Re: Re: Trouble Caching an Image
by Baz (Friar) on Sep 04, 2002 at 22:05 UTC
    Thanks, I replaced that code and it works now (I was just using a script I found on the web - I'm trying to get my head around 304 and this script included it). Anyway, I've added in the 304 part and that loop is now entered on subsequent calls - which is what I want. Now I need to get it working for SVG, which will be fun...