Flickr::Roles::Caching - Caching behaviors for the Flickr::Tools
CPAN: 1.22
Development: 1.22_01
package Flickr::Tools::of-some-kind; use Flickr::API::of-some-similar-kind; with qw(Flickr::Roles::Caching); sub getSomething-from-flickr { my ($self, $args) = @_; my $pre_expire = 0; $self->_set_cache_hit(1); if (defined($args->{clear_cache}) and $args->{clear_cache}) { $pre_expire = 1; } $self->_set_cache_key('meaningful-cache-key'); $data = $self->_cache->get($self->cache_key, expire_if => sub { $pre_expire } ); if (!defined $data) { $data = $self->{_api}->some-api-call; $self->_set_cache_hit(0); $self->_cache->set( $self->cache_key, $data, $self->cache_duration); } return $data; }
use Flickr::Tools::of-some-kind; my $tool = Flickr::Tools::of-some-kind->new(cache_duration => 3600, ...); say $tool->cache_duration; # will print 3600 $tool->cache_duration(300); # set the cache duration to 300 seconds $tool->getSomething-from-flickr; if ($tool->cache_hit) { say "gotSomething from cache"; } else { say "had to go to Flickr to getSomthing"; } $tool->getSomething-else-from-flickr(clear_cache => 1, arg1 => val1, arg2 => val2...);
This module adds a caching role for the Flickr::Tools packages.
cache_duration
The duration, in seconds, for the cache to keep the information. When the cache expires, it will re-fetch the data from Flickr if you request it again.
cache_hit
Returns whether the last cache get was from cache or fetched into the cache.
cache_key
This is the last used key into the cache. It is here, but it probably doesn't return what you think it will.
_cache
This is a reference to a CHI cache kept in the Flickr::Tool object.
CHI, Perl 5.10 and Moo.
None known of, yet.
Yes
Louis B. Moore <lbmoore@cpan.org>
Copyright (C) 2015 Louis B. Moore <lbmoore@cpan.org>
This program is released under the Artistic License 2.0 by The Perl Foundation. http://www.perlfoundation.org/artistic_license_2_0
To install Flickr::Tools, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Flickr::Tools
CPAN shell
perl -MCPAN -e shell install Flickr::Tools
For more information on module installation, please visit the detailed CPAN module installation guide.