Click here to get back home

HTTP::Cache module

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
HTTP::Cache module Mattias Holmlund 09-26-2004
Get Chitika Premium
Posted by Mattias Holmlund on September 26, 2004, 8:37 am
Please log in for more thread options
Hi,

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).
}
else
{
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?

Regards,

Mattias Holmlund



Similar ThreadsPosted
Accessing the Memoize cache April 2, 2005, 1:15 am
file upload, multipart form, and cgi::cache April 21, 2006, 7:01 am
IIS + Cache + W2003 + HTML header problem May 8, 2006, 8:24 am
need help with HTTP-WebTest module, tutorials or examples September 8, 2007, 1:19 am
install HTML::Template - Problem reading cache file / Bad file number July 24, 2004, 7:55 pm
XML-RPC over HTTP with SSL January 17, 2005, 10:08 pm
Using HTTP::Proxy September 23, 2004, 5:41 am
HTTP::ProxySelector March 17, 2006, 9:51 am
HTTP::Proxy and not using 127.0.0.1 May 11, 2006, 6:10 pm
HTTP::TreeBuilder problems July 29, 2004, 12:19 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap