Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

Caching pages with Perl

Need to store frequently accessed pages



6:18 pm on Aug 12, 2004 (gmt 0)

10+ Year Member

Hello, I need to cache pages in my server to reduce server load. I currently implemented the following script in my php pages and need to do the same with PERL

$cachefile = "cache/".$title.".html";

if (file_exists($cachefile))
{ include ($cachefile);


Page with html and database here

$buffer = ob_get_contents();
$fp = fopen($cachefile, 'w');
fwrite($fp, $buffer);

This script checks if the cached page exists and shows it instad of executing the rest of the page.

But if the page does not exist, then it opens a buffer and saves all the output into a page. It writes the page into the server so the next time it is called.

How can I do that in Perl. I have a script that consumes a lot of resources. If possible, I would like to place it before it calls the script, but that would involve passing variables through one script to another.

Is there an easy way to do so?

Thanks in advance



6:20 pm on Aug 13, 2004 (gmt 0)

10+ Year Member

Use the Storable module and check if the file exists (as you did in your php script). Works like a champ and is fast even on my celeron 500.


6:28 pm on Aug 13, 2004 (gmt 0)

10+ Year Member

Have a look at Cache::Cache and Cache::FileCache. There are many more Cache::XXXCache classes that store cached data in different ways (files, shmem, ...).



Featured Threads

Hot Threads This Week

Hot Threads This Month