« blib/lib/auto/share/dist/Cmd-Dwarf/app/lib/Dwarf/Plugin/AnyEvent/Redis.pm
↑ Summary
blib/lib/auto/share/dist/Cmd-Dwarf/app/lib/Dwarf/Plugin/Log/Dispatch.pm »
| 1 | package Dwarf::Plugin::Cache::Memcached::Fast; | ||
| 2 | use Dwarf::Pragma; | ||
| 3 | use Dwarf::Util qw/add_method/; | ||
| 4 | use Cache::Memcached::Fast; | ||
| 5 | |||
| 6 | sub init { | ||
| 7 | my ($class, $c, $opt) = @_; | ||
| 8 | $opt ||= {}; | ||
| 9 | $opt->{compress_threshold} ||= 100_000; | ||
| 10 | $opt->{default_memcached} ||= 'page'; | ||
| 11 | |||
| 12 | add_method($c, memcached => sub { | ||
| 13 | my ($self, $key) = @_; | ||
| 14 | $key ||= $opt->{default_memcached}; | ||
| 15 | |||
| 16 | my $conf = $self->conf('memcached') | ||
| 17 | or return; | ||
| 18 | |||
| 19 | $self->{'dwarf.memcached'} ||= do { | ||
| 20 | my $repo; | ||
| 21 | for my $key (keys %{ $conf }) { | ||
| 22 | $repo->{$key} = Cache::Memcached::Fast->new({ | ||
| 23 | servers => [ { address => $conf->{$key}->{server} } ], | ||
| 24 | namespace => $conf->{$key}->{namespace}, | ||
| 25 | compress_threshold => $opt->{compress_threshold}, | ||
| 26 | }); | ||
| 27 | } | ||
| 28 | $repo; | ||
| 29 | }; | ||
| 30 | |||
| 31 | my $memcached = $self->{'dwarf.memcached'}; | ||
| 32 | return $memcached->{$key} if exists $memcached->{$key}; | ||
| 33 | return; | ||
| 34 | }); | ||
| 35 | } | ||
| 36 | |||
| 37 | 1; |