#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
use Memoize qw(memoize unmemoize);
use Memoize::Storable;
my $filename = './memory.tmp';
tie my %cache => 'Memoize::Storable', $filename;
memoize 'function', SCALAR_CACHE => [HASH => \%cache];
print "".function(1), "\n";
print "".function(1), "\n";
print "".function(2), "\n"; # Changed original order
print "".function(1), "\n";
unmemoize 'function';
sub function {
my $wtf = shift;
print "I am the $wtf function\n";
return "anything $wtf";
}
####
I am the 1 function
anything 1
anything 1
I am the 2 function
anything 2
anything 1
##
##
anything 1
anything 1
anything 2
anything 1