I know you already know all of this, but i replied to you
because it seemed like the place. ;) I just had to take a
stab at this:
use strict;
use warnings;
use LWP::Simple;
use Cache::MemoryCache;
my $cache = Cache::MemoryCache->new({
namespace => 'MyNamespace',
default_expires_in => 60,
});
for (1..3) {
my $page = $cache->get('perlmonks');
unless ($page) {
warn "fetching from web\n";
$page = get('http://perlmonks.org');
$cache->set('perlmonks', $page, "1 minute" );
} else {
warn "fetching from cache\n";
}
}
The for loop is just to actually show that subsequent
fetches (after the first) come from the memory cache and
not the web. Use Cache::FileCache if you want
persistence past the life of script execution.
Honestly, as easy as this is ... it's still 'plumbing'.
I would like to see a 'LWP::Cache' module as long as it is
a transparent wrapper around LWP and Cache::Cache. Why not? ;)
jeffa
L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)
|