HTTP::Cache module

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!


I have written a perl module that I want to publish on CPAN. The module
implements a cache for http requests. It provides a single method get
that fetches a url via http. The result of each get is stored in a
cache on disk, and if the same url has been requested before, the
proper ETag and If-Modified-Since headers are sent to the http server.
The server can then respond that the object in the cache is up-to-date
and HTTP::Cache will return a cached version of the data instead of
fetching it from the server. This speeds up the HTTP get and saves
bandwidth for both the server and the client.

The module is very simple to use. Simply create a HTTP::Cache object
and call the get-method on the returned object to fetch a url. You do
not have to care if the data is fetched from the server or from the
cache (but you can find out if you want to know).

Sample usage:

my $c = HTTP::Cache->new( {
BasePath  => "/tmp/cache", # Directory to store the cache in.
MaxAge    => 8*24,         # How many hours should items be
# kept in the cache after they
# were last accessed?
# Default is 8*24.
Verbose   => 1,            # Print messages to STDERR.
# Default is 0.
UserAgent => "my-spider",  # The user-agent string to use.
# Default is "perl-http-cache".
} );

my( $content, $error ) = $c->get( $url );

if( defined( $content ) )
# Data retrieved and stored in $content.
# $error indicates if the data was found in the cache (0)
# if it was fetched from the server but equal to the cache (1)
# or if it was fetched from the server and different from the
# cache (2).
print STDERR "Failed to fetch $url. " .
"Error returned by server: $error";

Does anyone object to putting this module on CPAN or is it redundant?
Is HTTP::Cache a good name for it?


Mattias Holmlund

Site Timeline