perl -MMemoize -MMemoize::Expire -E " \ sub f { ('X',int rand 100) }; \ tie my %cache => 'Memoize::Expire', NUM_USES => 3; \ memoize 'f', LIST_CACHE => 'MERGE', \ SCALAR_CACHE => [ HASH => \%cache ]; \ for (1..6) { say f() }" #### perl -MMemoize -MMemoize::Expire -MSerializeValues -E " \ sub f { ('X',int rand 100) }; \ tie my %subcache => 'Memoize::Expire', NUM_USES => 3; \ tie my %cache => 'SerializeValues', \%subcache; \ memoize 'f', LIST_CACHE => [ HASH => \%cache ], \ SCALAR_CACHE =>'MERGE' ; \ for (1..6) { say f() }" #### #!/usr/bin/env perl package SerializeValues; require Tie::Hash; @ISA = qw(Tie::ExtraHash); use strict; use warnings; use Storable qw[freeze thaw]; sub TIEHASH { my ($class, $child_hash) = @_; return bless [$child_hash], $class; } sub STORE { $_[0][0]{$_[1]}= freeze $_[2] } sub FETCH { thaw $_[0][0]{$_[1]} }