Hey::Cache - Cache data multiple data structures
use Hey::Cache; my $cache = Hey::Cache->new( Namespace => 'WeatherApp2000', # string (optional, default='default') CacheFile => 'fun_cache_file.xml', # file path and name (optional, default='cache.xml') AutoSync => 1, # boolean (optional, default=1) Expires => 300, # seconds (optional, default=86400) ); $cache->set( Name => '98501', # sets the name/key of the piece of data Value => { Temperature => 17, # sets the data that you wish to cache Condition => 'Rain', High => 19, Low => 7 }, Expires => 600, # optional, defaults to what was set in the constructor above ); $value = $cache->get( Name => '98501' ); # returns what you had set ... enough time passes (at least 10 minutes, according to the "Expires" value) ... $value = $cache->get( Name => '98501' ); # returns undef because it has expired $value = $cache->get( Name => '98501', Expires => 86400 ); # returns what you had set # because it is newer than a day
Helps with regular data caching. It's targetted for items that are in hash references, primarly.
my $cache = Hey::Cache->new( Namespace => 'WeatherApp2000', # string (optional, default='default') CacheFile => 'fun_cache_file.xml', # file path and name (optional, default='cache.xml') AutoSync => 1, # boolean (optional, default=1) Expires => 300, # seconds (optional, default=86400) );
Default value is "default".
Default value is "cache.xml".
Default value is 1.
Default value is 86400 (24 hours).
$cache->sync;
Sends the data out to file. If AutoSync is disabled (per call or in the constructor), this will manually save out your data to the cache file. If AutoSync is enabled, this will happen automatically.
$weather = $cache->get( Name => '98501' ); $weather = $cache->get( Name => '98501', Expires => 600 ); # override the expiration of the item
Gets the named data from the cache.
The name of the item to return. This name was specified in the $cache->set function.
Age in number of seconds that would be acceptable. If the cached item is newer than this value, it will return the item. If the cached item is older than the value, it will return undef.
$value = { Temperature => 14, High => 15, Low => 12 }; $cache->get( Name => '98501', Value => $value );
Set a value (scalar, hash, etc) by name into the cache.
The name. Name of the item. Use this as a key to get it later with the $cache->get function.
The value. It works best if it's a reference to something, especially a hash.
Boolean. Defaults to the value specified in the constructor, which defaults to true.
Defaults to the current time. If it is useful to set a different timestamp, you can do it here. This value is in epoch seconds.
Defaults to the value specified in the constructor. Sets the expiration time for this item. Expiration is stored with each item separately, so you can assign different expirations for different items.
Dusty Wilson, <hey-cache-module@dusty.hey.nu>
Copyright (C) 2006 by Dusty Wilson <http://dusty.hey.nu/>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.
5 POD Errors
The following errors were encountered while parsing the POD:
=cut found outside a pod block. Skipping to next block.
To install Hey::Cache, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Hey::Cache
CPAN shell
perl -MCPAN -e shell install Hey::Cache
For more information on module installation, please visit the detailed CPAN module installation guide.