NAME

PEF::CacheLRU - a simple, fast implementation of LRU cache in pure perl

SYNOPSIS

   use PEF::CacheLRU;

   my $cache = PEF::CacheLRU->new($max_num_of_entries);

   $cache->set($key => $value);

   $value = $cache->get($key);

   $removed_value = $cache->remove($key);

DESCRIPTION

PEF::CacheLRU is a simple, fast implementation of an in-memory LRU cache in pure perl. It is inspired by Cache::LRU but works faster.

METHODS

PEF::CacheLRU->new($max_num_of_entries)

Creates a new cache object. The only parameter is the maximum number of entries to be stored within the cache object.

$cache->get($key)

Returns the cached object if exists, or undef otherwise.

$cache->set($key => $value)

Stores the given key-value pair.

$cache->remove($key)

Removes data associated to the given key and returns the old value, if any.

$cache->size

Returns used cache size.

$cache->max_size

Returns cache capacity.

Authors

This module was written and is maintained by:

  • PEF Developer <pef-secure@yandex.ru>

Speed

What is the difference between Cache::LRU and this module?

Using slightly modified benchmark from Cache::LRU I get:

cache_hit:
                Rate    Cache::LRU PEF::CacheLRU
Cache::LRU     872/s            --          -52%
PEF::CacheLRU 1815/s          108%            --

cache_set:
                Rate    Cache::LRU PEF::CacheLRU
Cache::LRU    5.81/s            --          -22%
PEF::CacheLRU 7.44/s           28%            --

cache_set_hit:
               Rate    Cache::LRU PEF::CacheLRU
Cache::LRU    155/s            --          -35%
PEF::CacheLRU 238/s           54%            --

SEE ALSO

Cache::LRU

LICENSE

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See <http://www.perlfoundation.org/artistic_license_2_0>