Weather::OpenWeatherMap::Cache - Cache manager for OpenWeatherMap results
# Usually used via Weather::OpenWeatherMap
A simple cache manager for Weather::OpenWeatherMap results.
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".
The duration (in seconds) cache files are considered valid; defaults to 1200.
1200
Takes a list of Weather::OpenWeatherMap::Result objects and caches to "dir".
Returns the number of items cached.
Takes a Weather::OpenWeatherMap::Request and attempts to retrieve a (non-expired) cached Weather::OpenWeatherMap::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):
time()
my $result; if (my $cached = $cache->retrieve($request)) { $result = $cached->object }
Subclasses can override the following methods to alter cache behavior.
Returns a list of Path::Tiny objects representing (what appear to be) Weather::OpenWeatherMap cache files.
Walk our "dir", removing any items that appear to belong to the cache.
Returns the list of removed paths (as strings).
Takes a scalar containing serialized cache data and returns a Perl object or data structure.
Uses Storable by default.
Given a Weather::OpenWeatherMap::Request or Weather::OpenWeatherMap::Result, removes relevant stale cache data.
If passed no arguments, calls "expire_all".
Called by "retrieve" before object retrieval.
Returns true if a cached object was expired.
Expires any stale cache files found in "dir".
Takes a Weather::OpenWeatherMap::Request or Weather::OpenWeatherMap::Result and returns boolean true if the object is cached.
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.
Takes a Perl object or data structure and returns serialized cache data suitable for writing to disk.
Jon Portnoy <avenj@cobaltirc.org>
To install Weather::OpenWeatherMap, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Weather::OpenWeatherMap
CPAN shell
perl -MCPAN -e shell install Weather::OpenWeatherMap
For more information on module installation, please visit the detailed CPAN module installation guide.