1 |
3 |
ahitrov@rambler.ru |
package Contenido::Cache::Memcached; |
2 |
|
|
|
3 |
|
|
use strict; |
4 |
|
|
use warnings 'all'; |
5 |
|
|
use base qw(Cache::BaseCache); |
6 |
|
|
|
7 |
|
|
use Contenido::Cache::MemcachedBackend; |
8 |
|
|
use Contenido::Errors qw(warn); |
9 |
|
|
use Contenido::Logger; |
10 |
|
|
|
11 |
|
|
|
12 |
|
|
########################################### |
13 |
|
|
# Cache::BaseCache interface implementation |
14 |
|
|
########################################### |
15 |
|
|
|
16 |
|
|
sub new { |
17 |
|
|
my ($class, $opts) = @_; |
18 |
|
|
my $self = Cache::BaseCache::_new(@_); |
19 |
|
|
$self->_set_backend(Contenido::Cache::MemcachedBackend->new($opts)); |
20 |
|
|
$self->_complete_initialization; |
21 |
|
|
$self; |
22 |
|
|
} |
23 |
|
|
|
24 |
|
|
sub Clear { |
25 |
|
|
my ($self) = @_; |
26 |
|
|
$self->_not_implemented('Clear'); |
27 |
|
|
} |
28 |
|
|
|
29 |
|
|
sub Purge { |
30 |
|
|
my ($self) = @_; |
31 |
|
|
$self->_not_implemented('Purge'); |
32 |
|
|
} |
33 |
|
|
|
34 |
|
|
sub Size { |
35 |
|
|
my ($self) = @_; |
36 |
|
|
$self->_not_implemented('Size'); |
37 |
|
|
} |
38 |
|
|
|
39 |
|
|
sub set { |
40 |
|
|
my $self = shift; |
41 |
|
|
my ($key, $data, $expires_in) = @_; |
42 |
|
|
|
43 |
|
|
if ($expires_in eq 'never') { |
44 |
|
|
Contenido::Logger->instance->warning("No 'expires_in' specified, caching impossible for key '$key'"); |
45 |
|
|
$self->SUPER::set($key, $data, 84600); |
46 |
|
|
return; |
47 |
|
|
} |
48 |
|
|
$self->SUPER::set(@_); |
49 |
|
|
} |
50 |
|
|
|
51 |
|
|
|
52 |
|
|
################### |
53 |
|
|
# Internal routines |
54 |
|
|
################### |
55 |
|
|
|
56 |
|
|
sub _not_implemented { |
57 |
|
|
my ($self, $meth) = @_; |
58 |
|
|
warn "WARNING! ".ref($self)."::$meth not implemented\n"; |
59 |
|
|
} |
60 |
|
|
|
61 |
|
|
|
62 |
|
|
1; |