Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

cache::historical(3pm) [debian man page]

Historical(3pm) 					User Contributed Perl Documentation					   Historical(3pm)

NAME
Cache::Historical - Cache historical values SYNOPSIS
use Cache::Historical; my $cache = Cache::Historical->new(); # Set a key's value on a specific date $cache->set( $dt, $key, $value ); # Get a key's value on a specific date my $value = $cache->get( $dt, $key ); # Same as 'get', but if we don't have a value at $dt, but we # do have values for dates < $dt, return the previous # historic value. $cache->get_interpolated( $dt, $key ); DESCRIPTION
Cache::Historical caches historical values by key and date. If you have something like historical stock quotes, for example 2008-01-02 msft 35.22 2008-01-03 msft 35.37 2008-01-04 msft 34.38 2008-01-07 msft 34.61 then you can store them in Cache::Historical like my $cache = Cache::Historical->new(); my $fmt = DateTime::Format::Strptime->new( pattern => "%Y-%m-%d"); $cache->set( $fmt->parse_datetime("2008-01-02"), "msft", 35.22 ); $cache->set( $fmt->parse_datetime("2008-01-03"), "msft", 35.37 ); $cache->set( $fmt->parse_datetime("2008-01-04"), "msft", 34.38 ); $cache->set( $fmt->parse_datetime("2008-01-07"), "msft", 34.61 ); and retrieve them later by date: my $dt = $fmt->parse_datetime("2008-01-03"); # Returns 35.37 my $value = $cache->get( $dt, "msft" ); Even if there's no value available for a given date, but there are historical values that predate the requested date, "get_interpolated()" will return the next best historical value: my $dt = $fmt->parse_datetime("2008-01-06"); # Returns undef, no value available for 2008-01-06 my $value = $cache->get( $dt, "msft" ); # Returns 34.48, the value for 2008-01-04, instead. $value = $cache->get_interpolated( $dt, "msft" ); Methods new() Creates the object. Takes the SQLite file to put the date into as an additional parameter: my $cache = Cache::Historical->new( sqlite_file => "/tmp/mydata.dat", ); The SQLite file defaults to $HOME/.cache-historical/cache-historical.dat so if you have multiple caches, you need to use different SQLite files. time_range() # List the time range for which we have values for $key my($from, $to) = $cache->time_range( $key ); keys() # List all keys my @keys = $cache->keys(); values() # List all the values we have for $key, sorted by date # ([$dt, $value], [$dt, $value], ...) my @results = $cache->values( $key ); clear() # Remove all values for a specific key $cache->clear( $key ); # Clear the entire cache $cache->clear(); last_update() # Return a DateTime object of the last update of a given key my $when = $cache->last_update( $key ); since_last_update() # Return a DateTime::Duration object since the time of the last # update of a given key. my $since = $cache->since_last_update( $key ); LEGALESE
Copyright 2007-2011 by Mike Schilli, all rights reserved. This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself. AUTHOR
2007, Mike Schilli <cpan@perlmeister.com> perl v5.10.1 2011-04-27 Historical(3pm)

Check Out this Related Man Page

Mason::Plugin::Cache(3pm)				User Contributed Perl Documentation				 Mason::Plugin::Cache(3pm)

NAME
Mason::Plugin::Cache - Provide component cache object and filter VERSION
version 0.04 SYNOPSIS
my $result = $.cache->get('key'); if (!defined($result)) { ... compute $result ... $.cache->set('key', $result, '5 minutes'); } ... % $.Cache('key2', '1 hour') {{ <!-- this will be cached for an hour --> % }} DESCRIPTION
Adds a "cache" method and "Cache" filter to access a cache (CHI) object with a namespace unique to the component. INTERP PARAMETERS
cache_defaults Hash of parameters passed to cache constructor. Defaults to driver=>'File', root_dir => 'DATA_DIR/cache' which will create a basic file cache under Mason's data directory. cache_root_class Class used to create a cache. Defaults to CHI. COMPONENT CLASS METHODS
cache Returns a new cache object with the namespace set to the component's path. Parameters to this method, if any, are combined with cache_defaults and passed to the cache_root_class constructor. The cache object is memoized when no parameters are passed. my $result = $.cache->get('key'); REQUEST METHODS
cache Same as calling "cache" on the current component class. This usage will be familiar to Mason 1 users. my $result = $m->cache->get('key'); FILTERS
Cache ($key, $options, [%cache_params]) Caches the content using "$self->cache" and the supplied cache $key. $options is a scalar or hash reference. If a scalar, it is treated as the "expires_in" duration and passed as the third argument to "set". If it is a hash reference, it may contain name/value pairs for both "get" and "set". %cache_params, if any, are passed to "$self->cache". % $.Cache($my_key, '1 hour') {{ <!-- this will be cached for an hour --> % }} % $.Cache($my_key, { expire_if => sub { $.refresh } }, driver => 'RawMemory') {{ <!-- this will be cached until $.refresh is true --> % }} If neither $key nor $options are passed, the key is set to 'Default' and the cache never expires. % $.Cache() {{ <!-- cache this forever, or until explicitly removed --> % }} SUPPORT
The mailing list for Mason and Mason plugins is mason-users@lists.sourceforge.net. You must be subscribed to send a message. To subscribe, visit https://lists.sourceforge.net/lists/listinfo/mason-users <https://lists.sourceforge.net/lists/listinfo/mason-users>. You can also visit us at "#mason" on <irc://irc.perl.org/#mason>. Bugs and feature requests will be tracked at RT: http://rt.cpan.org/NoAuth/Bugs.html?Dist=Mason-Plugin-Cache bug-mason-plugin-cache@rt.cpan.org The latest source code can be browsed and fetched at: http://github.com/jonswar/perl-mason-plugin-cache git clone git://github.com/jonswar/perl-mason-plugin-cache.git SEE ALSO
Mason AUTHOR
Jonathan Swartz <swartz@pobox.com> COPYRIGHT AND LICENSE
This software is copyright (c) 2011 by Jonathan Swartz. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. perl v5.14.2 2011-06-24 Mason::Plugin::Cache(3pm)
Man Page