Tie::Cache::LRU::Expires - Extends Tie::Cache::LRU with expiring


Tie-Cache-LRU-Expires documentation  | view source Contained in the Tie-Cache-LRU-Expires distribution.

Index


NAME

Top

Tie::Cache::LRU::Expires - Extends Tie::Cache::LRU with expiring

SYNOPSIS

Top

	use Tie::Cache::LRU::Expires;

	tie %cache, 'Tie::Cache::LRU::Expires', EXPIRES => 10, ENTRIES => 1000;
        $cache_obj = tied %cache;

        for(1..1000) {
           $cache{$_}="test $_";
        }
        sleep 4;
        for(1000..1500) {
           $cache{$_}="test $_";
        }

        print $cache_obj->lru_size(),"\n";		# access to the
							# number of entries
							# used in the LRU
							# cache.

        sleep 4;
	for(1..10) { print $cache{$_},"\n"; }
	for(1100..1110) { print $cache{$_},"\n"; }
        sleep 4;
	for(1..10) { print $cache{$_},"\n"; }    	# expired (undefs).
	for(1100..1110) { print $cache{$_},"\n"; }
        sleep 4;
	for(1100..1110) { print $cache{$_},"\n"; }	# now also expired.

	# Clearing the cache

	%cache=();







DESCRIPTION

Top

This is an expiring LRU cache, using Tie::Cache::LRU. Each entry in this cache expires after 'EXPIRES' seconds (default 3600). The cache is in RAM (see Tie::Cache::LRU). ENTRIES provides the maximum number of entries in the Tie::Cache::LRU cache.

It works by checking if a cached entry hasn't expired. If it has, undef is returned, otherwise it's value. If the entry wasn't cached, undef is also returned (of course). Expired entries will eventually drop of the LRU; or, if referenced will (as can be expected, otherwise they wouldn't be referenced) be refreshed.

NB! If entries keep being referenced and are expired, but never refreshed, they will never leave the LRU!

SEE ALSO

Top

Tie::Cache::LRU.

USAGE

Top

See SYNOPSIS. Too simple to explain.

AUTHOR

Top

Hans Oesterholt-Dijkema <oesterhol@cpan.org>


Tie-Cache-LRU-Expires documentation  | view source Contained in the Tie-Cache-LRU-Expires distribution.