lua-lru

LRU cache in Lua

$ luarocks install lua-lru

lua-lru, LRU cache in Lua

LRU cache is implemented using a doubly linked list and
a hash map. Hash Map maps a key to a corresponding tuple.
Doubly Linked List is used to store list of tuples
(value, previous, next, key, size_in_bytes).
Key is needed in a tuple to be able to remove an element from
the hash map. Field size_in_bytes is optional and is used
if sizes in bytes are counted (and constrained) as well as
the number of elements.

Create an instance of LRU cache for 100 elements:

lru = require 'lru'
cache = lru.new(100)

Create an instance of LRU cache for 100 elements of
1000 bytes totally:

lru = require 'lru'
cache = lru.new(100, 1000)

Methods:

* cache:set(key, value, [size_in_bytes])
* cache:get(key)
* cache:delete(key)
* cache:pairs() or pairs(cache) for Lua >= 5.2

Versions

1.0-19 years ago14,323 downloads

Dependencies

lua >= 5.1

Dependency for

ljdns, luafather, mooncrafts, telegram-bot-api

Labels

Manifests