in reply to Re: Wanted: LWP::Cache
in thread Wanted: LWP::Cache
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.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"; } }
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)
|
|---|