A cache utilizing a simple LRU (Least Recently Used) policy. The items managed by this cache must respond to the key method. Attempts to optimize reads rather than inserts!
LRU semantics are enforced by inserting the items in a queue. The lru item is always at the tail. Two special sentinels (head, tail) are used to simplify (?) the code.
Usage
TODO: If you have an example of using this, please submit. -T
Author(s)
- George Moschovitis <gm@navel.gr>
- Anastasios Koutoumanos <ak@navel.gr>
Methods
Classes and Modules
Module LRUCache::ItemClass LRUCache::Sentinel
Attributes
[R] | head | the head sentinel and the tail sentinel, tail.prev points to the lru item. |
[RW] | max_items | the maximum number of items in the cache. |
[R] | tail | the head sentinel and the tail sentinel, tail.prev points to the lru item. |
Public Class methods
new(max_items)
[ source ]
Public Instance methods
[](key)
[ source ]
Lookup an item in the cache.
[]=(key, item)
[ source ]
The inserted item is considered mru!
clear()
[ source ]
Clear the cache.
delete(key)
[ source ]
Delete an item from the cache.
first()
[ source ]
The first (mru) element in the cache.
Alias for last