You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Markus Wolf <pe...@perl-archiv.de> on 2005/08/17 10:55:45 UTC
Filter-Question : Caching
Hallo,
I'm writing my first Apache 2 - Filter yesterday - it works fine,
but i have one problem with caching.
This is my conf-entry
<Files ~ "\.html">
PerlOutputFilterHandler ApacheMY::session
</Files>
my problem is, that the filter only work, when I save or "touch"
the html-file again - the filter seems to cache the output with the
help of the "last change date" of the file.
What have I to do, that the filter is process every time, a
site is called?
/\/\arkus
http://www.perlunity.de
Re: Filter-Question : Caching
Posted by Markus Wolf <pe...@perl-archiv.de>.
Hallo,
first - thank for your answer - i try it - but it do no not
work - here are some code of the Filter
#Name
package ApacheKSKBB::session;
#Pfade
use lib "/usr/lib/perl5/Apache2" ;
#Module
#use strict;
#use warnings;
use Apache::Filter ();
use Apache::RequestRec ();
use Apache::RequestUtil ();
use APR::Table ();
use Apache::Const -compile => qw(OK);
use constant BUFF_LEN => 1024;
############################################################################
# Filter
############################################################################
sub handler {
my $f = shift;
my $line = '' ;
local $/ = undef ;
srand() ;
###
#File verarbeiten
#unless ($f->ctx) {
$f->r->headers_out->unset('Content-Length');
$f->r->headers_out->unset('If-Modified-Since') ;
$f->r->headers_out->add( 'Cache-Control' =>
'no-store,no-cache,must-revalidate' ) ;
$f->r->headers_out->add( 'Pragma' => 'no-cache' );
$f->ctx(1);
#}
my $file = $f->r->filename() ;
my $header = $f->r->as_string() ;
while ($f->read(my $buffer, BUFF_LEN)) {
$line .= $buffer ;
}
my $nocache=time ;
$f->print("<pre>$nocache \n $file \n $header \n</pre> $line<!--
cache:$nocache:NEW -->") ;
###
#Neu
if ($f->seen_eos) {
$f->remove() ;
}
###
#Ende
return Apache::Const::OK ;
the output is
1124351373
/var/www/virtual/s-shopping.de/htdocs/index1.html
GET /index1.html?asdasd121212121 HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/vnd.ms-excel, application/msword, application/vnd.ms-powerpoint,
application/x-shockwave-flash, */*
Accept-Language: de
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR
1.0.3705)
Host: www.s-shopping.de
Connection: Keep-Alive
HTTP/1.1 (null)
Last-Modified: Thu, 18 Aug 2005 07:42:08 GMT
ETag: "120fc2-3f12-59aa9400"
Accept-Ranges: bytes
Cache-Control: no-store,no-cache,must-revalidate
Pragma: no-cache
I think the problem is, that the scrpipt is defined as a
filter
> <Files ~ "\.html">
> PerlOutputFilterHandler ApacheMY::session
>
> </Files>
is there an solution for an Filter-Script? The header-entry
If-Modified-Since - is out of the header, but i makes no difference.
Thank you ...
/\/\arkus
http://www.perlunity.de
Re: Filter-Question : Caching
Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
Markus Wolf wrote:
> Hallo,
>
> I'm writing my first Apache 2 - Filter yesterday - it works fine,
> but i have one problem with caching.
>
> This is my conf-entry
> <Files ~ "\.html">
> PerlOutputFilterHandler ApacheMY::session
>
> </Files>
>
> my problem is, that the filter only work, when I save or "touch"
> the html-file again - the filter seems to cache the output with the
> help of the "last change date" of the file.
This is probably because your browser is sending If-Modified-Since
http GET requests and not re-requesting the file since it doesn't appear
to have changed. (see http://perl.apache.org/docs/general/correct_headers/correct_headers.html#Conditional_GET)
You can verify this is the case by using a simpler http client, like
LWP, wget, curl, etc and you should see your filter being run every
single time.
> What have I to do, that the filter is process every time, a
> site is called?
If you want to make sure the browsers _never_ cache your content (make really
sure that's what you want) and use $r->no_cache(1)
http://perl.apache.org/docs/2.0/api/Apache2/RequestUtil.html#C_no_cache_
But really, it's fairly possible that in your case, this is an annoyance for
development, but actually a fairly _good_ feature in general.
--------------------------------------------------------------------------------
Philippe M. Chiasson m/gozer\@(apache|cpan|ectoplasm)\.org/ GPG KeyID : 88C3A5A5
http://gozer.ectoplasm.org/ F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3A5A5