Initialize the HTTP cache. Takes a single parameter which is a
hashref containing named arguments to the object.
The directory where the cache is stored must be writable. It must also only contain files created by HTTP::Cache::Transparent.
|Initializing from use-line||
An alternative way of initializing HTTP::Cache::Transparent is to supply
parameters in the use-line. This allows you to write
which is exactly equivalent to
The advantage to using this method is that you can do
or even set the environment variable PERL5OPT
and have all the http-requests performed by myscript.pl go through the cache without changing myscript.pl
The HTTP::Cache::Transparent inserts two special headers in the HTTP::Response object. These can be accessed via the HTTP::Response::header()-method.
X-Cached This header is inserted and set to 1 if the response is delivered from the cache instead of from the server. X-Content-Unchanged This header is inserted and set to 1 if the content returned is the same as the content returned the last time this url was fetched. This header is always inserted and set to 1 when the response is delivered from the cache.
This module has a number of limitations that you should be aware of before using it.
- There is no upper limit to how much diskspace the cache requires. The only limiting mechanism is that data for urls that havent been requested in the last MaxAge hours will be removed from the cache the next time the program exits. - Currently, only get-requests that store the result in memory (i.e. do not use the option to have the result stored directly in a file or delivered via a callback) is cached. I intend to remove this limitation in a future version. - The support for Ranges is a bit primitive. It creates a new object in the cache for each unique combination of url and range. This will work ok as long as you always request the same range(s) for a url. - The cache doesnt properly check and store all headers in the HTTP request and response. Therefore, if you request the same url repeatedly with different sets of headers (cookies, accept-encoding etc), and these headers affect the response from the server, the cache may return the wrong response.
The cache is stored on disk as one file per cached object. The filename is equal to the md5sum of the url and the Range-header if it exists. The file contains a set of key/value-pairs with metadata (one entry per line) followed by a blank line and then the actual data returned by the server.
The last modified date of the cache file is set to the time when the cache object was last requested by a user.
Mattias Holmlund, <$firstname -at- $lastname -dot- se> <http://www.holmlund.se/mattias/>
A git repository containing the source for this module can be found via http://git.holmlund.se/
Copyright (C) 2004-2007 by Mattias Holmlund
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.4 or, at your option, any later version of Perl 5 you may have available.
|perl v5.20.3||HTTP::CACHE::TRANSPARENT (3)||2012-10-25|