Changeset 564
- Timestamp:
- 06/18/07 17:50:53 (2 years ago)
- Files:
-
- trunk/api/perl/ChangeLog (modified) (1 diff)
- trunk/api/perl/lib/Cache/Memcached.pm (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/api/perl/ChangeLog
r558 r564 1 * Add hook support, and define a few hooks for use in gathering 2 statistics. 1 2007-06-18: version 1.22 2 3 * lost connection handling broken due to wrong %sock_map indexing 4 http://rt.cpan.org/Public/Bug/Display.html?id=27181 5 fix from RHESA 3 6 4 7 * let parser_class be configured as a constructor option, trunk/api/perl/lib/Cache/Memcached.pm
r558 r564 25 25 bucketcount _single_sock _stime 26 26 connect_timeout cb_connect_fail 27 parser_class hooks27 parser_class 28 28 }; 29 29 … … 36 36 37 37 use vars qw($VERSION $HAVE_ZLIB $FLAG_NOSIGNAL); 38 $VERSION = "1.2 1";38 $VERSION = "1.22"; 39 39 40 40 BEGIN { … … 83 83 $self->{namespace} = $args->{namespace} || ''; 84 84 $self->{namespace_len} = length $self->{namespace}; 85 $self->{hooks} = {};86 85 87 86 return $self; … … 162 161 } 163 162 164 my %sock_map; # s calaraddr -> "$ip:$port";163 my %sock_map; # stringified-$sock -> "$ip:$port" 165 164 166 165 sub _dead_sock { 167 166 my ($sock, $ret, $dead_for) = @_; 168 if (my $ipport = $sock_map{ \$sock}) {167 if (my $ipport = $sock_map{$sock}) { 169 168 my $now = time(); 170 169 $host_dead{$ipport} = $now + $dead_for 171 170 if $dead_for; 172 171 delete $cache_sock{$ipport}; 173 delete $sock_map{ \$sock};172 delete $sock_map{$sock}; 174 173 } 175 174 @buck2sock = (); … … 179 178 sub _close_sock { 180 179 my ($sock) = @_; 181 if (my $ipport = $sock_map{ \$sock}) {180 if (my $ipport = $sock_map{$sock}) { 182 181 close $sock; 183 182 delete $cache_sock{$ipport}; 184 delete $sock_map{ \$sock};183 delete $sock_map{$sock}; 185 184 } 186 185 @buck2sock = (); … … 413 412 return 0 unless $sock; 414 413 415 $self->run_hook('delete_start', $self);416 417 414 $self->{'stats'}->{"delete"}++; 418 415 $key = ref $key ? $key->[1] : $key; … … 426 423 } 427 424 428 $self->run_hook('delete_end', $self);429 430 425 return $res eq "DELETED\r\n"; 431 426 } … … 452 447 return 0 unless $sock; 453 448 454 $self->run_hook('set_start', $self);455 456 449 use bytes; # return bytes from length() 457 450 … … 498 491 $self->{'stat_callback'}->($stime, $etime, $sock, $cmdname); 499 492 } 500 501 $self->run_hook('set_end', $self);502 493 503 494 return $res eq "STORED\r\n"; … … 552 543 $self->{'stats'}->{"get_multi"}++; 553 544 554 $self->run_hook('get_start', $self);555 556 545 my %val; # what we'll be returning a reference to (realkey -> value) 557 546 my %sock_keys; # sockref_as_scalar -> [ realkeys ] … … 561 550 $sock = $self->sock_to_host($self->{'_single_sock'}); 562 551 unless ($sock) { 563 $self->run_hook('get_start', $self);564 552 return {}; 565 553 } … … 596 584 597 585 _load_multi($self, \%sock_keys, \%val); 598 599 $self->run_hook('get_end', $self);600 586 601 587 if ($self->{'debug'}) { … … 920 906 } 921 907 922 sub run_hook {923 my Cache::Memcached $self = shift;924 my $hookname = shift || return;925 926 my $hook = $self->{hooks}->{$hookname};927 return unless $hook;928 929 eval { $hook->(@_) };930 931 warn "Cache::Memcached hook '$hookname' threw error: $@\n" if $@;932 }933 934 sub add_hook {935 my Cache::Memcached $self = shift;936 my $hookname = shift || return;937 938 if (@_) {939 $self->{hooks}->{$hookname} = shift;940 } else {941 delete $self->{hooks}->{$hookname};942 }943 }944 945 908 1; 946 909 __END__
