class Cache::LRU { use Hash::Ordered; our $num_caches = 0; # class data (unused in this example) my $x = Hash::Ordered->new; # private instance data has UInt $max_size = 20; # public instance data method set ( Str $key, $value ) { if ( $x->exists($key) ) { $x->delete($key); } elsif ( $x->keys > $max_size ) { $x->shift; } $x->set( $key, $value ); } method get ( Str $key) { return unless $x->exists($key); return $x->set( $key, $x->delete($key) ); } }