Cache::Isolator - transaction and concurrency manager of cache systems.
use Cache::Isolator; use Cache::Memcached::Fast; my $isolator = Cache::Isolator->new( cache => Cache::Memcached::Fast->new(...), concurrency => 4, ); my $key = 'query:XXXXXX'; $isolator->get_or_set( $key, sub { # This callback invoked when miss cache get_from_db($key); }, 3600 );
Cache::Isolator is transaction and concurrency manager of cache systems. Many cache systems have Thundering Herd problem. If a cache has expired, concentration of access to the database may happen. This will cause a system failure. Cache::Isolator can control the concentration of load.
Following parameters are recognized.
Required. Cache::Memcached::Fast object or similar interface object.
Optional. Number of get_or_set callback executed in parallel. If many process need to run callback, they wait until lock becomes released or able to get values. Defaults to 1. It means no concurrency.
Optional. The seconds for busy loop interval. Defaults to 0.01 seconds.
Optional. When the value is being set zero, get_or_set will be waiting until lock becomes released. When the value is being set positive integer value, get_or_set will die on reached trial count. Defaults to 0.
Optional. The seconds until lock becomes released. Defaults to 30 seconds.
Optional. if early_expires_ratio was set to greater than zero, Cache::Isolator stores to duplicate the cache. One of them is set to expire earlier than normal. Cache::Isolator gets the cache has been set to expire early in the specified percentage. This feature can prevent the cache from disappearing all together. Defaults is "0".
my $cache = Cache::Isolator->new( early_expires_ratio => 10, # This means 1/10 ratio );
Optional. Seconds earlier expiration. Defaults is 10.
$callback is subroutine reference. That invoked when cache miss occurred.
Masahiro Nagano <kazeburo {at} gmail.com>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Cache::Isolator, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Cache::Isolator
CPAN shell
perl -MCPAN -e shell install Cache::Isolator
For more information on module installation, please visit the detailed CPAN module installation guide.