Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Re: Caching html files

by Anonymous Monk
on Sep 03, 2001 at 17:14 UTC ( [id://109862]=note: print w/replies, xml ) Need Help??


in reply to Re: Caching html files
in thread Caching html files

one solution (of which there are _many_) is to change the way in which your Perl script returns data.

One method that I implemented once was to use a combination of Apache mod_rewrite, apache .htaccess files and of course Perl.


I installed the mod_rewrite module into Apache. Created an .htaccess file that basically did the following:
- if user is looking for a file or is requesting a url that has been previously asked for, check in the /cache for a file (or a file that represents the data matching the url). If the file exists then redirect the users browser to that page (or premade cached file) -> the end result is the user never hits the cgi (perl script)
- if the user is looking for a file that doesnt exist then redirect them to the perl script which will create a lock file and then create the requested file to disk and also to screen (by redirecting STDOUT). The next person to request the page/url will have it presented to them instantly

If another user asks for the same file whilst the page is being generated, then simply get your Perl script to skip over the file creation method (which is being done by another perl process running - you simply check for the existence of a lock file) and simply display the output to screen. Hopefully once the perl script has finished creating the file on disk (and removed the lock file) any subsequent requests will be redirected to the file and not the cgi/perl script.

In addition to the caching it might also be a good idea to track (using the apache logs) what requests are the most common, if you have 50 urls/pages that are dynamically created and are the most commonly requested pages then create another script that pre-creates them offline (and refreshes them when the data changes).

hth.

Dave......
-->daves_listreader@hotmail.com

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://109862]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2024-04-24 07:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found