|
Revision 16079, 1.9 kB
(checked in by daisuke, 5 years ago)
|
|
Pod::Coverage
|
-
Property svn:keywords set to
Id
|
| Line | |
|---|
| 1 | # $Id$ |
|---|
| 2 | |
|---|
| 3 | package Data::Valve::BucketStore::Memcached; |
|---|
| 4 | use Moose; |
|---|
| 5 | use Moose::Util::TypeConstraints; |
|---|
| 6 | |
|---|
| 7 | extends 'Data::Valve::BucketStore::Object'; |
|---|
| 8 | |
|---|
| 9 | subtype '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 | |
|---|
| 20 | coerce '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 | |
|---|
| 30 | has '+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 | |
|---|
| 44 | no Moose; |
|---|
| 45 | |
|---|
| 46 | 1; |
|---|
| 47 | |
|---|
| 48 | __END__ |
|---|
| 49 | |
|---|
| 50 | =head1 NAME |
|---|
| 51 | |
|---|
| 52 | Data::Valve::BucketStore::Memcached - Memcached Backend |
|---|
| 53 | |
|---|
| 54 | =head1 DESCRIPTION |
|---|
| 55 | |
|---|
| 56 | Data::Valve::BucketStore::Memcached uses Memcached as its storage backend, |
|---|
| 57 | and allows multiple processes to work together. |
|---|
| 58 | |
|---|
| 59 | You 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 | |
|---|
| 73 | This module also provides locking mechanism by means of KeyedMutex. |
|---|
| 74 | You 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 | |
|---|
| 89 | This allows all coordinating processes to share the same mutex, and you will |
|---|
| 90 | get "correct" throttling information |
|---|
| 91 | |
|---|
| 92 | =head1 METHODS |
|---|
| 93 | |
|---|
| 94 | =head2 try_push |
|---|
| 95 | |
|---|
| 96 | =head2 reset |
|---|
| 97 | |
|---|
| 98 | =cut |
|---|