lieven has asked for the wisdom of the Perl Monks concerning the following question:

Hi I'm working with Perl to bild CGI web aplications and problems with i think browser cahche. It's a code with +- 2000 lines so i won't post the whole script. But I think the problem is some where in the HTTP header.

First I load the headers and footers from another server using the following:

# User agent object aanmaken use LWP::UserAgent; use HTTP::Request; my $ua = LWP::UserAgent->new; my $request = HTTP::Request->new<br>('GET','http://www.telfort.nl/inc/ +headers/header_belmobiel.php'); my $response = $ua->request($request); my $header = $response->as_string(); ### Opschonen $header #my $headtemp; #($headtemp,$header)= split(/\!/,$header,2); #$header = "<!".$header; my $request = HTTP::Request->new<br>('GET','http://www.telfort.nl/inc/ +footers/footer_belmobiel.php'); my $response = $ua->request($request); my $footer = $response->as_string();
##########################################
I cut the Headers using split, not elegant but effective.

Then I write my own Header:

print "Cache-Control: no-cache\nPragma: no-cache\n"; ## caching tegen +te gaan (speciaal wegens proxy-servers) #print $cgi->header; print "Content-type: text/html\n\n"; #### header van telfort ##### print $header;
After this I open a Template to show the content.

If you use the same search parameters in the script it keeps giving different results. If you start with parameters that are wrong it keeps telling the information was not found. Even when you change the parameters to absolute right ones.

Does anyone know the solution or can anyone give me directions to search for solutions. It could be a installation fault on the server but i'm don't have much knowledge of servers and software like apache. Thanx

edited by ybiC: balanced <code> tags

Replies are listed 'Best First'.
Re: cache problems
by liz (Monsignor) on Aug 14, 2003 at 14:38 UTC
    I think there is a \n too many here:
    print "Content-type: text/html\n\n";
    what you print with the next:
    print $header;
    will become part of the body that you're sending out. Is that intentional?

    Liz

Re: cache problems
by JPaul (Hermit) on Aug 14, 2003 at 15:57 UTC
    At one point, many moons ago, while developing CGI and finding that I had caching issues (Although I don't recall the specifics of what exactly was getting cached when I didn't want it to) I added this to the CGI header:
    print $q->header(-expires => '-1d');
    I've never had a caching issue since. Perhaps this is overkill, and perhaps its not necessary, but at the time this was the only option that appeared to make a difference.

    For what its worth,
    JP
    -- Alexander Widdlemouse undid his bellybutton and his bum dropped off --

Re: cache problems
by valdez (Monsignor) on Aug 14, 2003 at 17:09 UTC