Why not adopt me?
NAME
Weather::OpenWeatherMap::Cache - Cache manager for OpenWeatherMap results
SYNOPSIS
# Usually used via Weather::OpenWeatherMap
DESCRIPTION
A simple cache manager for Weather::OpenWeatherMap results.
ATTRIBUTES
dir
The directory cache files are saved in.
Defaults to using a temporary directory that is cleaned up during object destruction (via Path::Tiny / File::Temp).
If you specify a directory, no automated cleanup is done other than normal object expiry checks during calls to "retrieve".
expiry
The duration (in seconds) cache files are considered valid; defaults to 1200
.
METHODS
High-level methods
cache
Takes a Weather::OpenWeatherMap::Result and caches it to "dir".
retrieve
Takes a Weather::OpenWeatherMap::Request and attempts to retrieve a (non-expired) cached result.
Returns false if no item was found.
If successful, the return value is a simple struct-like object with two attributes, cached_at (the time()
that the cached item was saved) and object (the relevant Weather::OpenWeatherMap::Result object):
my $result;
if (my $cached = $cache->retrieve($request)) {
$result = $cached->object
}
Low-level methods
Subclasses can override the following methods to alter cache behavior.
clear
Walk our "dir", removing any items that appear to belong to the cache.
Returns the list of removed paths (as strings).
deserialize
Takes a scalar containing serialized cache data and returns a Perl object or data structure.
Uses Storable by default.
expire
Takes a Weather::OpenWeatherMap::Request or Weather::OpenWeatherMap::Result and removes relevant stale cache data.
Called by "retrieve" before object retrieval.
Returns true if a cached object was expired.
is_cached
Takes a Weather::OpenWeatherMap::Request or Weather::OpenWeatherMap::Result and returns boolean true if the object is cached.
make_path
Takes a Weather::OpenWeatherMap::Request or Weather::OpenWeatherMap::Result and returns an appropriate Path::Tiny object representing the path that would be used to cache or retrieve the object.
serialize
Takes a Perl object or data structure and returns serialized cache data suitable for writing to disk.
Uses Storable by default.
AUTHOR
Jon Portnoy <avenj@cobaltirc.org>