| Cache-Memcached-Indexable documentation | Contained in the Cache-Memcached-Indexable distribution. |
Cache::Memcached::Indexable::Logic::DigestSHA1 - a fine logic for Cache::Memcached::Indexable
use Cache::Memcached::Indexable::Logic::DigestSHA1;
use Cache::Memcached::Indexable;
my $logic = Cache::Memcached::Indexable::Logic::DigestSHA1->new;
$logic->set_max_power(0xff);
my $memd = Cache::Memcached::Indexable->new({
'servers' => [ "10.0.0.15:11211", "10.0.0.15:11212",
"10.0.0.17:11211", [ "10.0.0.17:11211", 3 ] ],
'debug' => 0,
'compress_threshold' => 10_000,
});
$memd->set_logic($logic);
or
my $memd = Cache::Memcache::Indexable->new({
'logic' => 'Cache::Memcached::Indexable::Logic::DigestSHA1',
'logic_args' => { set_max_power => 0xff },
'servers' => [ "10.0.0.15:11211", "10.0.0.15:11212",
"10.0.0.17:11211", [ "10.0.0.17:11211", 3 ] ],
'debug' => 0,
'compress_threshold' => 10_000,
});
This module is a kind of logic class for Cache::Memcached::Indexable.
It uses to get an original key through Digest::SHA1::sha1_hex() function
with your key.
You can set how many patterns do you want to use for the original key.
The $power must be a 16's power minus 1 (0xF, 0xFF, 0xFFF, 0xFFFF, 0xFFFFF ...).
Note that the $memd-keys()> will be taken too long time to return all your keys
if you set a huge number to this method.
Koichi Taniguchi <taniguchi@livedoor.jp>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Cache::Memcache::Indexable, Cache::Memcached::Indexable::Logic
| Cache-Memcached-Indexable documentation | Contained in the Cache-Memcached-Indexable distribution. |
package Cache::Memcached::Indexable::Logic::DigestSHA1; use strict; use warnings; use Carp; use Digest::SHA1 qw(sha1_hex); use base qw(Cache::Memcached::Indexable::Logic); our $VERSION = '0.02'; sub set_max_power { my($self, $power) = @_; unless (sprintf('%x', $power) =~ /^f+$/) { carp "max_power must be a 16's power minus 1 (like 0xFFFF)"; } $self->{_max_power} = $power; } sub max_power { my $self = shift; unless (exists $self->{_max_power}) { $self->{_max_power} = 0xFF; # XXX default } return $self->{_max_power}, } sub max_power_length { my $self = shift; unless ($self->{_max_power_length}) { $self->{_max_power_length} = length(sprintf('%x', $self->max_power)); } return $self->{_max_power_length}; } sub all_keys { my $self = shift; my $format = sprintf('%%0%dx', $self->max_power_length); map { sprintf($format, $_) } (0 .. $self->max_power); } sub find_branch_key { my($self, $key) = @_; return substr(sha1_hex($key), 0, $self->max_power_length); } 1; __END__