Class LRUCache
In: lib/facet/lru-cache.rb
Parent: Hash

Description

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

  ?

Author(s)

  • George Moschovitis <gm@navel.gr>
  • Anastasios Koutoumanos <ak@navel.gr>

Methods

[]   []=   clear   delete   first   last   lru   lru_append   lru_clear   lru_delete   lru_insert   lru_join   lru_touch   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

Public Instance methods

Lookup an item in the cache.

The inserted item is considered mru!

Clear the cache.

Delete an item from the cache.

The first (mru) element in the cache.

The last (lru) element in the cache.

lru()

Alias for last

Private Instance methods

Append a child item to a parent item in the lru list (Re)inserts the child in the list.

Clear the lru.

Delete an item from the lru list.

Insert an item

Join two items in the lru list. Return y to allow for chaining.

Touch an item, make mru! Returns the item.

[Validate]