07 Mar 2016 10:32:14 UTC
- Distribution: LWP-UserAgent-CHICaching
- Module version: 0.04
- Source (raw)
- Browse (raw)
- How to Contribute
- Repository (git clone)
- Testers (1728 / 6 / 0)
- KwaliteeBus factor: 1
- 100.00% Coverage
- License: perl_5
- Perl: v5.6.0
- Activity24 month
- Download (19.7KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest versionKJETILK Kjetil Kjernsmo
- COPYRIGHT AND LICENCE
LWP::UserAgent::Role::CHICaching - A role to allow LWP::UserAgent to cache with CHI
Compose it into a class, e.g.
package LWP::UserAgent::MyCacher; use Moo; extends 'LWP::UserAgent'; with 'LWP::UserAgent::Role::CHICaching', 'LWP::UserAgent::Role::CHICaching::SimpleKeyGen', 'LWP::UserAgent::Role::CHICaching::SimpleMungeResponse';
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.
Used to set the
CHIobject to be used as cache in the constructor.
The Request-URI of the request. When set, it will clear the
key, but should probably be left to be used internally for now.
Wrapping LWP::UserAgent's request method.
A boolean value to set whether the cache can be shared. The default is that it is.
A hashref that is passed to the
freshness_lifetimemethod of HTTP::Response, and used to determine the behaviour of the heuristic lifetime. By default, heuristic freshness lifetime is off, only standards-compliant freshness lifetime (i.e. based on the
Expiresheaders) are used.
The following are required by this role, but implemented elsewhere. See LWP::UserAgent::Role::CHICaching::SimpleKeyGen and LWP::UserAgent::Role::CHICaching::SimpleMungeResponse for further explanations.
The key to use for a response.
A method that returns true if the response may be cached even if it contains a
Varyheader, false otherwise. The HTTP::Response object will be passed to it as a parameter.
A method that takes the HTTP::Response from the client and an expires time in seconds and set the actual cache.
A method that takes the cached entry as an argument, and will return a HTTP::Response to return to the client.
Will only cache
GETrequests, and only successful responses.
The module does not validate and does not serve stale responses, even when it would be allowed to do so. It nevertheless does most of RFC7234.
Please report any bugs to https://github.com/kjetilk/p5-lwp-useragent-chicaching/issues.
Kjetil Kjernsmo <firstname.lastname@example.org>.
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.
This software is copyright (c) 2015, 2016 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.
Module Install Instructions
To install LWP::UserAgent::CHICaching, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell install LWP::UserAgent::CHICaching
For more information on module installation, please visit the detailed CPAN module installation guide.