class Kramdown::Utils::LRUCache
entry is added and the cache is full, the first entry is removed.
and re-inserting a key-value pair on access moves the key to the last position. When an
The cache relies on the fact that Ruby’s Hash class maintains insertion order. So deleting
A simple least recently used (LRU) cache.
def [](key)
def [](key) (val = @cache.delete(key)).nil? ? nil : @cache[key] = val end
def []=(key, value)
def []=(key, value) @cache.delete(key) @cache[key] = value @cache.shift if @cache.length > @size end
def initialize(size)
def initialize(size) @size = size @cache = {} end