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.
AttributesandMethods
"cache"
Used to set the "CHI" object to be used as cache in the constructor.
"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.
"is_shared"
A boolean value to set whether the cache can be shared. The default is that it is.
"heuristics_opts"
A hashref that is passed to the "freshness_lifetime" method 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 "Cache-Control" and "Expires" headers) are
used.
Implementedelsewhere
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.
"key", "clear_key"
The key to use for a response.
cache_vary($response)
A method that returns true if the response may be cached even if it contains a "Vary" header, false
otherwise. The HTTP::Response object will be passed to it as a parameter.
"cache_set($response, $expires_in)"
A method that takes the HTTP::Response from the client and an expires time in seconds and set the
actual cache.
finalize($cached)
A method that takes the cached entry as an argument, and will return a HTTP::Response to return to
the client.