You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by darren chamberlain <da...@boston.com> on 2000/06/22 15:47:41 UTC

Caching question: Dynamically generated output

Hello, all.

My question is probably more Apache-related than mod_perl related, but since
my output is being generated dynamically from a Perl module, I'll ask it here
first.

We are dynamically generating datebars for our sites using GD. The datebar
for the day is generated the first time a child process gets a request for
it. We are caching the resulting GIF in memory, send it out with an Expires
header, so that web clients and downstream caches can cache the resulting
datebar more easily. This server has been up for a few months, and we were
having no problems, until we decided to add an ETag header a few weeks ago.
Since then, after getting numerous complaints about the datebars not being
updated, we removed the ETag, but are still having the staleness complaints.

When viewed from within Navigator's Info window, the datebar image has the
correct expiration date set, and a Shift-Reload does procude the correct
image. We are sure it is a client-side caching issue (fresh requests
for it (with an empty cache) always produce the correct results), so I 
assume we are sending Expires headers incorrectly.

Here is a snippet of the headers we are sending:

    my $now  = time;
    my $time = $args{'date'} || $now;
    my $midnight = parsedate('midnight + 1 day', NOW=>$time);
    my $expires  = http_date($midnight);
    my $lastmod  = http_date($midnight - (60*60*24));

    $r->header_out('Expires' => $expires);
    my $maxage = $midnight - $now;
    $r->header_out('Cache-Control' => "max-age=$maxage, must-revalidate");

    $r->header_out('Last-Modified'  => $lastmod);
    $r->header_out('Content-length' => length($CACHE{$hashkey}));
    $r->content_type('image/gif');
    $r->send_http_header;

...and the image is sent.

(bash) $ HEAD http://date.boston.com/
200 OK
Cache-Control: max-age=51455
Date: Thu, 22 Jun 2000 13:42:25 GMT
Server: Apache/1.3.12 (Unix) mod_perl/1.21
Content-Length: 1582
Content-Type: image/gif
Expires: Fri, 23 Jun 2000 04:00:00 GMT
Last-Modified: Thu, 22 Jun 2000 04:00:00 GMT
Client-Date: Thu, 22 Jun 2000 13:44:37 GMT

Any ideas would be greatly appreciated. Thanks.

darren

-- 
Have an adequate day.

Re: Caching question: Dynamically generated output

Posted by Tim Sweetman <td...@aldigital.co.uk>.
Darren,

Try looking at what IE does around the cutoff point.
I'm not sure how well browers (and proxy caches) follow cache control
directives - I can't see anything wrong with your headers.

I don't know if there are any FAQs etc on this subject. Certainly I've
seen bad things happen with cookie expiry times on IE (similarly, if
cookies are set to expire "fairly soon", they tend to get chucked away
if users have incorrect time zone/time settings), and most sites seem to
use cookies that expire a Long Way into the future. Which is pretty
fishy.

This is arguably OT, but since cache control is related to performance,
and to making cookie-based authentication work properly, it seems pretty
relevant.

Cheers

--
Tim Sweetman