NAME
LWP::UserAgent::Role::CHICaching - A role to allow LWP::UserAgent to cache with CHI
SYNOPSIS
Compose it into a class, e.g.
package LWP::UserAgent::MyCacher;
use Moo;
extends 'LWP::UserAgent';
with 'LWP::UserAgent::Role::CHICaching';
DESCRIPTION
This is a role for creating caching user agents. When the client makes a request to the server, sometimes the response should be cached, so that no actual request has to be sent at all, or possibly just a request to validate the cache. HTTP 1.1 defines how to do this. This role makes it possible to use the very flexible CHI module to manage such a cache. See LWP::UserAgent::CHICaching for a finished class you can use.
Attributes and Methods
cache
-
Used to set the
CHI
object to be used as cache in the constructor. key
,clear_key
-
The key to use for a response. Defaults to the canonical URI of the request. May make sense to set differently in the future, but should probably be left alone for now.
request_uri
-
The Request-URI of the request. When set, it will clear the
key
, but should probably be left to be used internally for now. request
-
Wrapping LWP::UserAgent's request method.
LIMITATIONS
Will only cache GET
requests and only looks at the Cache-Control: max-age
header. Does not make any attempts to see if the response is invalid.
BUGS
Please report any bugs to https://github.com/kjetilk/p5-lwp-useragent-chicaching/issues.
AUTHOR
Kjetil Kjernsmo <kjetilk@cpan.org>.
ACKNOWLEDGEMENTS
It was really nice looking at the code of LWP::UserAgent::WithCache, when I wrote this.
Thanks to Matt S. Trout for rewriting this to a Role.
COPYRIGHT AND LICENCE
This software is copyright (c) 2015 by Kjetil Kjernsmo.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.