Changeset 24119
- Timestamp:
- 11/18/08 18:19:14 (7 weeks ago)
- Location:
- lang/perl/Method-Cached/trunk
- Files:
-
- 5 modified
-
MANIFEST (modified) (1 diff)
-
MANIFEST.SKIP (modified) (1 diff)
-
lib/Method/Cached.pm (modified) (3 diffs)
-
lib/Method/Cached/KeyRule.pm (modified) (4 diffs)
-
t/benchmark.pl (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/Method-Cached/trunk/MANIFEST
r22434 r24119 20 20 t/02-management.t 21 21 t/03-composite.t 22 t/97-boilerplate.t23 t/98-perlcritic.t24 t/99-pod.t25 22 t/benchmark.pl 26 23 t/perlcriticrc -
lang/perl/Method-Cached/trunk/MANIFEST.SKIP
r22434 r24119 16 16 ^[^/]+\.pl$ 17 17 ^\.shipit$ 18 ^t/9\d-.*\.t$ -
lang/perl/Method-Cached/trunk/lib/Method/Cached.pm
r22433 r24119 22 22 my $name = $pkg . '::' . *{$symbol}{NAME}; 23 23 my ($domain_name, $expires, $key_rule) = _parse_option(@{ $options }); 24 my $cref = { 25 name => $name, 26 code => $code, 27 domain => $domain_name, 28 expires => $expires, 29 key_rule => $key_rule, 30 }; 24 31 no strict 'refs'; 25 32 no warnings 'redefine'; 26 *{$name} = sub { 27 my @args = @_; 28 my $domain = $_DOMAINS{$domain_name} 29 ? $_DOMAINS{$domain_name} 30 : $_DEFAULT_DOMAIN; 31 $key_rule ||= $domain->{key_rule}; 32 my $key = Method::Cached::KeyRule::regularize($key_rule, $name, \@args); 33 my $storage = _storage($domain); 34 my $ret = $storage->get($key); 35 return wantarray ? @{ $ret } : ${ $ret }[0] if $ret; 36 my @ret = ($code->(@_)); 37 $storage->set($key, \@ret, $expires || 0); 38 return wantarray ? @ret : $ret[0]; 39 }; 33 *{$name} = sub { unshift @_, $cref; goto &_wrapper }; 40 34 } 41 35 … … 59 53 my $class = shift; 60 54 if (0 < @_) { 55 my $option = shift; 56 exists $option->{key_rule} && delete $option->{key_rule}; 61 57 $_DEFAULT_DOMAIN = { 62 58 %{ $_DEFAULT_DOMAIN }, 63 %{ +shift},59 %{ $option }, 64 60 }; 65 61 _inspect_storage_class($_DEFAULT_DOMAIN->{storage_class}); … … 120 116 $invalid && croak 121 117 'storage_class needs the following methods: new, set, get, delete or remove'; 118 } 119 120 sub _wrapper { 121 my $c = shift; 122 my $dname = $c->{domain}; 123 my $domain = $_DOMAINS{$dname} ? $_DOMAINS{$dname} : $_DEFAULT_DOMAIN; 124 my $rule = $c->{key_rule} || $domain->{key_rule}; 125 my $key = Method::Cached::KeyRule::regularize($rule, $c->{name}, [ @_ ]); 126 my $store = _storage($domain); 127 my $ret = $store->get($key); 128 return wantarray ? @{ $ret } : ${ $ret }[0] if $ret; 129 my @ret = ($c->{code}->(@_)); 130 $store->set($key, \@ret, $c->{expires} || 0); 131 return wantarray ? @ret : $ret[0]; 122 132 } 123 133 -
lang/perl/Method-Cached/trunk/lib/Method/Cached/KeyRule.pm
r22060 r24119 5 5 use Digest::SHA qw/sha1_base64/; 6 6 use JSON::XS; 7 use Storable qw/freeze/;7 use Storable; 8 8 use Scalar::Util qw/refaddr/; 9 9 … … 16 16 my $key; 17 17 for my $rule (@{$key_rule}) { 18 $key = '';19 18 $key = ref $rule ? $rule->(@_) : &{$rule}(@_); 20 19 } … … 31 30 my ($method_name, $args) = @_; 32 31 our $ENCODER ||= JSON::XS->new->convert_blessed(1); 33 *UNIVERSAL::TO_JSON = sub { freeze \@_ };32 *UNIVERSAL::TO_JSON = sub { Storable::nfreeze \@_ }; 34 33 my $json = $ENCODER->encode($args->[0]); 35 34 undef *UNIVERSAL::TO_JSON; … … 54 53 local $^W = 0; 55 54 our $ENCODER ||= JSON::XS->new->convert_blessed(1); 56 *UNIVERSAL::TO_JSON = sub { freeze \@_ };55 *UNIVERSAL::TO_JSON = sub { Storable::nfreeze \@_ }; 57 56 my $json = $ENCODER->encode($args); 58 57 undef *UNIVERSAL::TO_JSON; -
lang/perl/Method-Cached/trunk/t/benchmark.pl
r24086 r24119 11 11 { servers => [qw/ 127.0.0.1:11211 /] }, 12 12 ], 13 key_rule => 'SERIALIZE', # SERIALIZE / LIST14 13 }, 15 14 -domains => { … … 19 18 { servers => [qw/ 127.0.0.1:11211 /] }, 20 19 ], 21 key_rule => ' SERIALIZE', # SERIALIZE / LIST20 key_rule => 'LIST', # SERIALIZE / LIST 22 21 }, 23 22 'fastmmap' => { … … 27 26 unlink_on_exit => 1, 28 27 ], 29 key_rule => ' SERIALIZE', # SERIALIZE / LIST28 key_rule => 'LIST', # SERIALIZE / LIST 30 29 }, 31 30 },
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)