Changeset 558
- Timestamp:
- 05/14/07 17:32:53 (2 years ago)
- Files:
-
- trunk/api/perl/ChangeLog (modified) (1 diff)
- trunk/api/perl/lib/Cache/Memcached.pm (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/api/perl/ChangeLog
r538 r558 1 * Add hook support, and define a few hooks for use in gathering 2 statistics. 3 1 4 * let parser_class be configured as a constructor option, 2 5 defaulting to XS if available, else regular. (unless trunk/api/perl/lib/Cache/Memcached.pm
r556 r558 25 25 bucketcount _single_sock _stime 26 26 connect_timeout cb_connect_fail 27 parser_class 27 parser_class hooks 28 28 }; 29 29 … … 83 83 $self->{namespace} = $args->{namespace} || ''; 84 84 $self->{namespace_len} = length $self->{namespace}; 85 $self->{hooks} = {}; 85 86 86 87 return $self; … … 412 413 return 0 unless $sock; 413 414 415 $self->run_hook('delete_start', $self); 416 414 417 $self->{'stats'}->{"delete"}++; 415 418 $key = ref $key ? $key->[1] : $key; … … 423 426 } 424 427 428 $self->run_hook('delete_end', $self); 429 425 430 return $res eq "DELETED\r\n"; 426 431 } … … 447 452 return 0 unless $sock; 448 453 454 $self->run_hook('set_start', $self); 455 449 456 use bytes; # return bytes from length() 450 457 … … 491 498 $self->{'stat_callback'}->($stime, $etime, $sock, $cmdname); 492 499 } 500 501 $self->run_hook('set_end', $self); 493 502 494 503 return $res eq "STORED\r\n"; … … 543 552 $self->{'stats'}->{"get_multi"}++; 544 553 554 $self->run_hook('get_start', $self); 555 545 556 my %val; # what we'll be returning a reference to (realkey -> value) 546 557 my %sock_keys; # sockref_as_scalar -> [ realkeys ] … … 549 560 if ($self->{'_single_sock'}) { 550 561 $sock = $self->sock_to_host($self->{'_single_sock'}); 551 return {} unless $sock; 562 unless ($sock) { 563 $self->run_hook('get_start', $self); 564 return {}; 565 } 552 566 foreach my $key (@_) { 553 567 my $kval = ref $key ? $key->[1] : $key; … … 582 596 583 597 _load_multi($self, \%sock_keys, \%val); 598 599 $self->run_hook('get_end', $self); 584 600 585 601 if ($self->{'debug'}) { … … 904 920 } 905 921 906 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 } 907 944 908 945 1;
