The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

WWW::Mechanize::Plugin::Cache - Automatic request caching for WWW::Mechanize::Pluggable

VERSION

This document describes WWW::Mechanize::Plugin::Cache version 0.0.1

SYNOPSIS

    # With this plugin installed:
    use WWW::Mechanize::Pluggable;
    my $cached_mech = new WWW::Mechanize::Pluggable new_cache=>1;
    $mech->get("http://yahoo.com");   # Fetched from Web
    $mech->get("http://yahoo.com");   # Fetched from cache

    # To use an old cache:
    my $cache = Cache::FileCache->new(cache_root=>'/old/cache/root');
    my $cached_mech = new WWW::Mechanize::Pluggable cache=>$cache;
    $mech->get("http://yahoo.com");   # Fetched from the old cache

DESCRIPTION

This plugin adds caching functionality to WWW::Mechanize::Pluggable. It duplicates the functionality of WWW::Mechanize::Cached; you can have WWW::Mechanize::Pluggable set up the cache for you, or reuse a previously-filled cache.

INTERFACE

new

The new method (with this plugin installed) supports two new options:

  • new_cache

    If supplied, this argument tells WWW::Mechanize::Pluggable to create and initialize a new cache.

  • cache => $cache

    If supplied, reuses an old cache. $cache must be an initialized object conforming to the Cache::FileCache interface.

init

Handles interfacing to WWW::Mechanize::Pluggable; installs the necessry methods and puts the cache in place. You do not want to call this method directly; WWW::Mechanize::Pluggable handles it for you.

prehook

This is a WWW::Mechanize::Pluggable prehook; don't call it yourself.

The prehook checks the cache argument, if any, from the new statement; if it finds that we want a cache (or we have a cache we're reusing), it sets it up as instructed, then turns cache creation off so it won't do it again.

If there is a cache, we look up the current request via the URL; if we find it, we use update_html to install the HTML we got from the cache, note that it came from the cache, and skip the call to Mech that would have actually accessed the page. If there's no cache, or if we didn't find the supplied URL in the cache, we just exit and let Mech::Pluggable go head and call the proper method.

posthook

This is a WWW::Mechanize::Pluggable prehook; don't call it yourself.

The posthook checks to see if the current content of the internal Mech object came from the cache; if so, it just exits. If not, it adds it to the cache.

cached

Tells you whether or not the last response came from the cache.

DIAGNOSTICS

The supplied object is not a valid cache

You supplied the cache argument, but the value supplied as the cache reference doesn't conform to the Cache::FileCache interface.

CONFIGURATION AND ENVIRONMENT

WWW::Mechanize::Plugin::Cache requires no configuration files or environment variables.

DEPENDENCIES

WWW::Mechanize::Pluggable, Cache::FileCache.

INCOMPATIBILITIES

None reported.

BUGS AND LIMITATIONS

No bugs have been reported.

The oages are currently stored as pages under URLs; this may need to be extended if we do extensive submit-based checking.

Please report any bugs or feature requests to bug-www-mechanize-plugin-cache@rt.cpan.org, or through the web interface at http://rt.cpan.org.

AUTHOR

Joe McMahon <mcmahon@yahoo-inc.com >

LICENCE AND COPYRIGHT

Copyright (c) 2005, Yahoo!. All rights reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.

DISCLAIMER OF WARRANTY

BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.