Loading ...
Sorry, an error occurred while loading the content.

Re: [mp2] A better way to set the Expire header

Expand Messages
  • Mike Cardwell
    ... This is the logic I use. It may help someone. Where $cache is the number of seconds to cache for: if( $cache ){ if( $r- protocol =~ /( d . d)/ && $1 = 1.1
    Message 1 of 5 , Jun 23, 2005
    • 0 Attachment
      * on the Thu, Jun 23, 2005 at 07:43:08AM -0400, Geoffrey Young wrote:

      > intelligently worrying about the browser cache will help your performance a
      > great deal. there's an entire section in the perl.apache.org docs about it.

      This is the logic I use. It may help someone.

      Where $cache is the number of seconds to cache for:

      if( $cache ){
      if( $r->protocol =~ /(\d\.\d)/ && $1 >= 1.1 ){
      # If http protocol is 1.1 or greater send a cache control header

      $r -> header_out( 'Cache-Control', "max-age=$cache" );
      } else {
      # Send an expires header instead
      my($sec,$min,$hour,$mday,$mon,$year,$wday,)=gmtime(time+$cache);
      my @days=qw(Sun Mon Tue Wed Thu Fri Sat Sun);
      my @months=qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
      my $date=sprintf("$days[$wday], %02d $months[$mon]
      %s %02d:%02d:%02d GMT",$mday,$year+1900, $hour, $min, $sec);

      $r -> header_out( 'Expires', $date );
      }
      } else {
      # Send a "don't cache" header
      $r->no_cache(1);
      }

      The reason I've got my own date stuff in there is because I've learnt to
      limit using third party modules as much as is reasonably possible when
      it comes to mod_perl. I was horrified at the memory usage of some of
      them when I first found Apache::Status ;)

      Mike

      --
      Digital photo printing: http://www.fotoserve.com/
    Your message has been successfully submitted and would be delivered to recipients shortly.