lights FAQ Forum github.com/luapower/lrucache
This package
lrucache

Data Structures
heap
queue
linkedlist
lrucache
rangelist

lrucache

Size-limited LRU cache in Lua


local lrucache = require'lrucache'

LRU cache limited by an abstract size. Values can have different sizes. When a new value is put in the cache and the cache is full, just enough old values are removed to make room for the new value and not exceed the cache max size.

API

lrucache([options]) -> cache create a new cache
cache.max_size <- size set the cache size limit
cache:clear() clear the cache
cache:free() destroy the cache
cache:free_value(val) value destructor (to be overriden)
cache:value_size(val) -> size get value size (to be overriden; returns 1)
cache:free_size() -> size size left until max_size
cache:get(key) -> val get a value from the cache by key
cache:remove(key) -> val remove a value from the cache by key
cache:remove_val(val) -> key remove a value from the cache
cache:remove_last() -> val remove the last value from the cache
cache:put(key, val) put a value in the cache, making room as needed

Last updated: 3 years ago | Edit on GitHub

Package:lrucache
Pkg type:Lua
Version: 921ae1d
Last commit:
Author: Cosmin Apreutesei
License: Public Domain

Requires: linkedlist 

Required by: resolver 


Top