Cache-Isolator
view release on metacpan or search on metacpan
lib/Cache/Isolator.pm view on Meta::CPAN
$result;
}
sub delete {
my ($self, $key) = @_;
$self->cache->delete($key.":earlyexp");
$self->cache->delete($key);
}
1;
__END__
=head1 NAME
Cache::Isolator - transaction and concurrency manager of cache systems.
=head1 SYNOPSIS
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
);
=head1 DESCRIPTION
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.
=head1 METHODS
=head2 new( %args )
Following parameters are recognized.
=over
=item cache
B<Required>. L<Cache::Memcached::Fast> object or similar interface object.
=item concurrency
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.
=item interval
Optional. The seconds for busy loop interval. Defaults to 0.01 seconds.
=item trial
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.
=item timeout
Optional. The seconds until lock becomes released. Defaults to 30 seconds.
=item early_expires_ratio
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. T...
my $cache = Cache::Isolator->new(
early_expires_ratio => 10, # This means 1/10 ratio
);
=item expires_before
Optional. Seconds earlier expiration. Defaults is 10.
=back
=head2 get_or_set( $key, $callback, $expires )
$callback is subroutine reference. That invoked when cache miss occurred.
=head2 get($key)
=head2 set($key, $value, $expires)
=head2 delete($key)
=head1 AUTHOR
Masahiro Nagano E<lt>kazeburo {at} gmail.comE<gt>
=head1 SEE ALSO
=head1 LICENSE
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
( run in 0.731 second using v1.01-cache-2.11-cpan-39bf76dae61 )