sub clear_cache { my @ids = sort {$count{$b} <=> $count{$a}} keys %count; splice @ids, 0, $reset_size-1; delete @cache{@ids}; %count = (); @count{keys %cache} = (0) x $reset_size; $size = $reset_size; } #### my $do_shift = 0; sub get_elem { my $id = shift; if (++$do_shift == 30) { shift_mru(); $do_shift = 0; } if (exists $count{$id}) { $count{$id} |= 0x80000000; return $cache{$id}; } else{ return; } } sub shift_mru { while (my ($id, $count) = each %count) { $count{$id} >>= 1; } }