line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# Copyright (c) 2008, 2009 Eugene Bragin |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# See COPYRIGHT section in pod text below for usage and distribution rights. |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
package Cache::Memcached::Tags; |
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
44586
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
76
|
|
10
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
139
|
|
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
11
|
use base 'Cache::Memcached'; |
|
2
|
|
|
|
|
14
|
|
|
2
|
|
|
|
|
3724
|
|
13
|
|
|
|
|
|
|
|
14
|
2
|
|
|
2
|
|
381068
|
use vars qw($VERSION); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
974
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
$VERSION = '0.02'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub add_tags { |
19
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
20
|
0
|
|
|
|
|
|
my $key = shift; |
21
|
0
|
|
|
|
|
|
my @tags = @_; |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
my $sock = $self->get_sock($key); |
24
|
0
|
|
|
|
|
|
foreach my $tag (@tags) { |
25
|
0
|
|
|
|
|
|
my $cmd = "tag_add $tag $self->{namespace}$key\r\n"; |
26
|
0
|
|
|
|
|
|
my $res = $self->_write_and_read($sock, $cmd); |
27
|
|
|
|
|
|
|
|
28
|
0
|
0
|
|
|
|
|
die "tag_add command returned ERROR, please make sure your memcached servers support tags: http://code.google.com/p/memcached-tags/" |
29
|
|
|
|
|
|
|
if $res eq "ERROR\r\n"; |
30
|
|
|
|
|
|
|
|
31
|
0
|
0
|
|
|
|
|
return 0 unless $res eq "TAG_STORED\r\n"; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
return 1; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
*add_tag = \&add_tags; |
38
|
|
|
|
|
|
|
*tag_add = \&add_tags; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub delete_by_tags { |
41
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
42
|
0
|
|
|
|
|
|
my @tags = @_; |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
my $cmd = 'tags_delete '. join(' ', @tags) ."\r\n"; |
45
|
0
|
|
|
|
|
|
my $items_deleted = 0; |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
my @hosts = @{$self->{'buckets'}}; |
|
0
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
foreach my $host (@hosts) { |
49
|
0
|
|
|
|
|
|
my $sock = $self->sock_to_host($host); |
50
|
0
|
|
|
|
|
|
my $res = $self->_write_and_read($sock, $cmd); |
51
|
0
|
0
|
|
|
|
|
warn "tag_add command returned ERROR, please make sure your memcached servers support tags: http://code.google.com/p/memcached-tags/" |
52
|
|
|
|
|
|
|
if $res eq "ERROR\r\n"; |
53
|
|
|
|
|
|
|
|
54
|
0
|
0
|
|
|
|
|
if ($res =~ /^(\d+) ITEMS_DELETED/) { |
55
|
0
|
|
|
|
|
|
$items_deleted += $1; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
return $items_deleted; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
*tag_delete = \&delete_by_tags; |
63
|
|
|
|
|
|
|
*tags_delete = \&delete_by_tags; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub set { |
66
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
67
|
0
|
|
|
|
|
|
my ($key, $value, $exptime, @tags) = @_; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
my $result = $self->SUPER::set($key, $value, $exptime); |
70
|
|
|
|
|
|
|
|
71
|
0
|
0
|
0
|
|
|
|
$self->add_tags($key, @tags) |
72
|
|
|
|
|
|
|
if @tags && $result; |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
return $result; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
__END__ |