Skip to content

Instantly share code, notes, and snippets.

@shiba-yu36
Created March 16, 2011 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shiba-yu36/872853 to your computer and use it in GitHub Desktop.
Save shiba-yu36/872853 to your computer and use it in GitHub Desktop.
MemoizeとAttribute::Memoize
use strict;
use warnings;
use Memoize qw(flush_cache);
my $t = test::Cache->new;
warn $t->rand_method('test2');
warn $t->rand_method('test1');
warn $t->rand_method('test2');
warn $t->rand_method('test1');
my $t2 = test::Cache->new;
warn $t2->rand_method('test2');
warn $t2->rand_method('test1');
flush_cache('test::Cache::rand_method');
warn $t->rand_method('test2');
warn $t2->rand_method('test2');
my $s = Sample->new;
warn $s->rand_method;
warn $s->rand_method;
package test::Cache;
use strict;
use warnings;
use base qw(Class::Accessor::Fast);
use Attribute::Memoize;
sub rand_method : Memoize {
my ($self, @list) = @_;
sleep 1;
return join('/', @list) . rand;
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment