What happens if you try to use it without calling init first? :)
Perhaps this situation might be avoided if BasePath could be specified at module load time, like so:
use HTTP::TransparentCache ( BasePath => '/tmp/cache*' );
Of course, this precludes two pieces of code in the same process from using different caches, but that restriction already exists with the current init model. In order to go beyond that, you'd have to allow cache configuration at the LWP::UserAgent object level, and I'm not quite sure how to best implement that.
Just food for though. Otherwise, congrats on the first release! The Transparency design is great.
-ofer
Mattias Holmlund wrote:
I have now uploaded my HTTP::TransparentCache module to CPAN. It
implements a persistent cache for HTTP get-requests. The module should
work seamlessly with all code that uses LWP to make HTTP requests. All
you have to do is add
use HTTP::TransparentCache; HTTP::TransparentCache::init({ BasePath => '/tmp/cache*' } );
at the top of your perl-program. After that, all get-requests, through LWP::Simple as well as the more advanced LWP-classes, will be cached.
This initial version does not cache any requests where the response is saved in a file by LWP::UserAgent or where data is returned with a callback. I intend to fix this in a later release, but for now these requests are sent directly to LWP::UserAgent bypassing the cache. Caching is also disabled for any requests containing a Range-header.
Please test the module with your favorite project. There is a simple example in examples/check_server that can be used to test if your http-server supports caching.
Note that the HTTP::TransparentCache module always checks with the server before returning data from the cache. This means that you never run the risk of receiving old data from the cache.
The module will hopefully show up on CPAN soon. In the meantime, you can
read the pod at http://www.holmlund.se/HTTP-TransparentCache.html and
download the code from
http://www.holmlund.se/HTTP-TransparentCache-0.1.tar.gz
/Mattias