|Syntactic Confectionery Delight|
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).