root/lang/perl/Data-Valve/trunk/lib/Data/Valve/BucketStore/Memcached.pm @ 16079

Revision 16079, 1.9 kB (checked in by daisuke, 5 years ago)

Pod::Coverage

  • Property svn:keywords set to Id
Line 
1# $Id$
2
3package Data::Valve::BucketStore::Memcached;
4use Moose;
5use Moose::Util::TypeConstraints;
6
7extends 'Data::Valve::BucketStore::Object';
8
9subtype 'Memcached'
10    => as 'Object'
11        => where {
12            my $h = $_;
13            foreach my $class qw( Cache::Memcached Cache::Memcached::Fast Cache::Memcached::libmemcached ) {
14                $h->isa($class) and return 1;
15            }
16            return ();
17        }
18;
19
20coerce 'Memcached'
21    => from 'HashRef'
22        => via {
23            my $h = $_;
24            my $module = $h->{module} || 'Cache::Memcached';
25            Class::MOP::load_class($module);
26            $module->new($h->{args});
27        }
28;
29
30has '+store' => (
31    isa      => 'Memcached',
32    coerce   => 1,
33    required => 1,
34    default  => sub {
35        Class::MOP::load_class('Cache::Memcached');
36        Cache::Memcached->new({
37            servers => [ '127.0.0.1:11211' ]
38        });
39    }
40);
41
42__PACKAGE__->meta->make_immutable;
43
44no Moose;
45
461;
47
48__END__
49
50=head1 NAME
51
52Data::Valve::BucketStore::Memcached - Memcached Backend
53
54=head1 DESCRIPTION
55
56Data::Valve::BucketStore::Memcached uses Memcached as its storage backend,
57and allows multiple processes to work together.
58
59You need to specify a memcached server in order for t to work:
60
61  Data::Valve->new(
62    bucket_store => {
63      module => "Memcached",
64      args => {
65        store => {
66          servers => [ '127.0.0.1:11211' ],
67          namespace => ...
68        }
69      }
70    }
71  );
72
73This module also provides locking mechanism by means of KeyedMutex.
74You should specify one at construction time:
75
76  Data::Valve->new(
77    bucket_store => {
78      module => "Memcached",
79      args   => {
80        mutex => {
81          args => {
82            sock => "host:port" # <-- here
83          }
84        }
85      }
86    }
87  );
88
89This allows all coordinating processes to share the same mutex, and you will
90get "correct" throttling information
91
92=head1 METHODS
93
94=head2 try_push
95
96=head2 reset
97
98=cut
Note: See TracBrowser for help on using the browser.