NAME

LWPx::UserAgent::Cached - Subclass of LWP::UserAgent that caches HTTP GET requests

VERSION

version 0.004

SYNOPSIS

use LWPx::UserAgent::Cached;
use CHI;

my $ua = LWPx::UserAgent::Cached->new(
    cache => CHI->new(
        driver => 'File', root_dir => '/tmp/cache', expires_in => '1d',
    ),
);
$ua->get('http://www.perl.org/');

DESCRIPTION

This module borrows the caching logic from WWW::Mechanize::Cached but without inheriting from WWW::Mechanize; instead it is just a direct subclass of LWP::UserAgent.

ATTRIBUTES

cache

Settable at construction, defaults to using CHI::Driver::RawMemory with an instance-specific hash datastore and a namespace with the current package name. You can use your own caching object here as long as it has get and set methods.

is_cached

Read-only accessor that indicates if the current request is cached or not.

cache_undef_content_length

Settable at construction or anytime thereafter, indicates whether we should cache content even if the HTTP Content-Length header is missing or undefined. Defaults to false.

cache_zero_content_length

Settable at construction or anytime thereafter, indicates whether we should cache content even if the HTTP Content-Length header is zero. Defaults to false.

cache_mismatch_content_length

Settable at construction or anytime thereafter, indicates whether we should cache content even if the length of the data does not match the HTTP Content-Length header. Defaults to true.

ref_in_cache_key

Settable at construction or anytime thereafter, indicates whether we should store the HTTP referrer in the cache key. Defaults to false.

positive_cache

Settable at construction or anytime thereafter, indicates whether we should only cache positive responses (HTTP response codes from 200 to 300 inclusive) or cache everything. Defaults to true.

SEE ALSO

LWP::UserAgent

Parent of this class.

WWW::Mechanize::Cached

Inspiration for this class.

HANDLERS

This module works by adding request_send and response_done handlers method that run on successful HTTP GET requests. If you need to modify or remove these handlers you may use LWP::UserAgent's handlers method.

SUPPORT

Perldoc

You can find documentation for this module with the perldoc command.

perldoc LWPx::UserAgent::Cached

Websites

The following websites have more information about this module, and may be of help to you. As always, in addition to those websites please use your favorite search engine to discover more resources.

Bugs / Feature Requests

Please report any bugs or feature requests through the web interface at https://github.com/mjgardner/LWPx-UserAgent-Cached/issues. You will be automatically notified of any progress on the request by the system.

Source Code

The code is open to the world, and available for you to hack on. Please feel free to browse it and play with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull from your repository :)

https://github.com/mjgardner/LWPx-UserAgent-Cached

git clone git://github.com/mjgardner/LWPx-UserAgent-Cached.git

AUTHOR

Mark Gardner <mjgardner@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2015 by ZipRecruiter.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.