Class LruHash
In: lib/rufus/lru.rb
Parent: Hash

A Hash that has a max size. After the maxsize has been reached, the least recently used entries (LRU hence), will be discared to make room for the new entries.

  require 'rubygems'
  require 'rufus/lru'

  h = LruHash.new(3)

  5.times { |i| h[i] = "a" * i }

  puts h.inspect # >> {2=>"aa", 3=>"aaa", 4=>"aaaa"}

  h[:newer] = "b"

  puts h.inspect # >> {:newer=>"b", 3=>"aaa", 4=>"aaaa"}

Methods

[]   []=   clear   delete   maxsize=   merge!   new   ordered_keys   remove_lru   touch  

Attributes

maxsize  [R] 

Public Class methods

Initializes a LruHash with a given maxsize.

Public Instance methods

Returns the keys with the lru in front.

Protected Instance methods

Makes sure that the hash fits its maxsize. If not, will remove the least recently used items.

Puts the key on top of the lru ‘stack’. The bottom being the lru place.

[Validate]