Cache::Range - Caches entries that are associated with an interval in a dataset
0.01
use Cache::Range; my $cache = Cache::Memory->new; # or any other Cache impl my $rcache = Cache::Range->new($cache); my $rows = [ 0..99 ]; $rcache->set($key, 0, $rows, '5 minutes'); # the end of the range is taken # from the length of the value $rcache->set($key, 110, $rows, '5 minutes'); my @entries = $rcache->get($key, 50, 90); for(my $i = 0; $i < @entries; $i += 2) { my ( $start, $data ) = @entries[$i, $i + 1]; # $start will be 50 here, and $data will contain # rows 50-90 }
This utility module builds off of a cache implementation to store data that are associated with an interval. For example, say you're querying a database for ranges of entries, and one query fetches the first one hundred rows. If on your next query you want rows twenty five through fifty back, the cache will give them to you, because those rows are contained within an interval you've already stored.
Creates a new Cache::Range object, which stores its entries in $cache.
$cache
Stores entries under $key which correspond to the interval $start - scalar(@$value) - 1, with an optional expiry time. NOTE: Because this module stores some internal state in the cache itself, I wouldn't recommend messing around with any cache entries prefixed by $key.
$key
$start
scalar(@$value) - 1
Returns a list of pairs; each pair is a previously cached entry that overlaps the requested region. The first member of the pair is the start of the interval, and the second is the data associated with that interval.
Rob Hoelz, rhoelz at inoc.com
rhoelz at inoc.com
Please report any bugs or feature requests to bug-Cache-Range at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Cache-Range. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-Cache-Range at rt.cpan.org
Copyright 2011 Rob Hoelz.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Cache
To install Cache::Range, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Cache::Range
CPAN shell
perl -MCPAN -e shell install Cache::Range
For more information on module installation, please visit the detailed CPAN module installation guide.