Created
March 16, 2011 17:08
-
-
Save shiba-yu36/872853 to your computer and use it in GitHub Desktop.
MemoizeとAttribute::Memoize
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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