olegwtf / p5-lwp-useragent-cached Goto Github PK
View Code? Open in Web Editor NEWLWP::UserAgent with agressive caching
LWP::UserAgent with agressive caching
LWP::UserAgent::Cached - LWP::UserAgent with simple caching mechanism ====================== When you process content from some website, you will get page one by one and extract some data from this page with regexp, DOM parser or smth else. Sometimes we makes errors in our data extractors and realize this only when all 1_000_000 pages were processed. We should fix our extraction logic and start all process from the beginning. Please STOP! How about cache? Yes, you can cache all responses and second, third and other attempts will be very fast. LWP::UserAgent::Cached is yet another LWP::UserAgent subclass with cache support. It stores cache in the files on local filesystem and if response already available in the cache returns it instead of making HTTP request.
I would suggest to add fpath to the nocache subref next to $response. it will make the code better like I want to check if the file isn't too old or the content contains </html>
or not etc.
if you need a patch, let me know.
Thanks.
I found all cookies are duplicated in requests if LWP::UserAgent:Cached module is used.
This issue could follow to problems on some web sites. You can reproduce this problem easily if you view requests in some kind of sniffer or use web site with cookies mirror.
I wrote a sample (see below) which first asks server mirror with Cache and second asks the same mirror without Cache.
`
use LWP::UserAgent;
use LWP::UserAgent::Cached;
my $ua = LWP::UserAgent::Cached->new(cache_dir => '.');
my $res;
$ua->cookie_jar({});
print "Cached LWP request test\n";
print "First request for cookies, Server response contains 'Set-Cookie: Name=Value'\n";
$ua->get('http://check.dosprn.com/version/set_cookie.php');
print "Second request to cookie mirror.\n";
$res=$ua->get('http://check.dosprn.com/version/cookie.php');
print "Cached LWP request result: " . $res->decoded_content . "\n";
print "\n\n";
print "Native LWP request test\n";
$ua = LWP::UserAgent->new();
$ua->cookie_jar({});
print "First request for cookies, Server response contains 'Set-Cookie: Name=Value'\n";
$ua->get('http://check.dosprn.com/version/set_cookie.php');
print "Second request to cookie mirror.\n";
$res=$ua->get('http://check.dosprn.com/version/cookie.php');
print "Native LWP request result: " .$res->decoded_content . "\n";
`
Check how caching works with different type of proxies
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.