CGI::Cache 1.4200 review

Download
by rbytes.net on

CGI::Cache is a Perl extension to help cache output of time-intensive CGI scripts. WARNING The interface as of version 1.01 has

License: Perl Artistic License
File size: 43K
Developer: Broc Seib
0 stars award from rbytes.net

CGI::Cache is a Perl extension to help cache output of time-intensive CGI scripts.

WARNING

The interface as of version 1.01 has changed considerably and is NOT compatible with earlier versions. A smaller interface change also occurred in version 1.20.

SYNOPSIS

Here's a simple example:

#!/usr/bin/perl

use CGI;
use CGI::Cache;

# Set up cache
CGI::Cache::setup();

my $cgi = new CGI;

# CGI::Vars requires CGI version 2.50 or better
CGI::Cache::set_key($cgi->Vars);

# This should short-circuit the rest of the loop if a cache value is
# already there
CGI::Cache::start() or exit;

print $cgi->header, "n";

print < body >
< p >

This prints to STDOUT, which will be cached.
If the next visit is within 24 hours, the cached STDOUT
will be served instead of executing this 'print'.

< /body >< /html >

EOF

Here's a more complex example:

use CGI;
use CGI::Cache;

my $query = new CGI;

# Set up a cache in /tmp/CGI_Cache/demo_cgi, with publicly
# unreadable cache entries, a maximum size of 20 megabytes,
# and a time-to-live of 6 hours.
CGI::Cache::setup( { cache_options =>
{ cache_root => '/tmp/CGI_Cache',
namespace => 'demo_cgi',
directory_umask => 077,
max_size => 20 * 1024 * 1024,
default_expires_in => '6 hours',
}
} );

# CGI::Vars requires CGI version 2.50 or better
CGI::Cache::set_key( $query->Vars );
CGI::Cache::invalidate_cache_entry()
if $query->param( 'force_regenerate' ) eq 'true';
CGI::Cache::start() or exit;

print "Content-type: text/htmlnn";

print < body >
< p >

This prints to STDOUT, which will be cached.
If the next visit is within 6 hours, the cached STDOUT
will be served instead of executing these 'prints'.
< /p >
EOF

CGI::Cache::pause();

print

CGI::Cache 1.4200 keywords