Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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

In reply to Re: Re: Caching html files by Anonymous Monk
in thread Caching html files by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (8)
As of 2024-04-16 16:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found