Giter Site home page Giter Site logo

p5-lwp-useragent-cached's Introduction

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.

p5-lwp-useragent-cached's People

Contributors

olegwtf avatar kni avatar

Stargazers

Fayland Lam avatar

Watchers

 avatar

p5-lwp-useragent-cached's Issues

path to nocache subref

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.

cookies are duplicated for all LWP requests

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";
`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.