Class | LRUCache
In: | lib/facets/more/lrucache.rb
Parent: | Hash

# LRUCache

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.

### Methods

[] []= clear delete first last lru new

### Classes and Modules

Module LRUCache::Item
Class LRUCache::Sentinel

### Attributes

head | [R] | the head sentinel and the tail sentinel, tail.prev points to the lru item.
max_items | [RW] | the maximum number of items in the cache.
tail | [R] | the head sentinel and the tail sentinel, tail.prev points to the lru item.

### Public Class methods

new(max_items)

### Public Instance methods

[](key)

Lookup an item in the cache.

[]=(key, item)

The inserted item is considered mru!

clear()

Clear the cache.

delete(key)

Delete an item from the cache.

first()

The first (mru) element in the cache.

last()

The last (lru) element in the cache.

lru()

Alias for last

[Validate]