class Hoss::Util::LruCache
@api private
Public Class Methods
new(max_size = 512, &block)
click to toggle source
# File lib/hoss/util/lru_cache.rb, line 24 def initialize(max_size = 512, &block) @max_size = max_size @data = Hash.new(&block) @mutex = Mutex.new end
Public Instance Methods
[](key)
click to toggle source
# File lib/hoss/util/lru_cache.rb, line 30 def [](key) @mutex.synchronize do val = @data[key] return unless val add(key, val) val end end
[]=(key, val)
click to toggle source
# File lib/hoss/util/lru_cache.rb, line 39 def []=(key, val) @mutex.synchronize do add(key, val) end end
length()
click to toggle source
# File lib/hoss/util/lru_cache.rb, line 45 def length @data.length end
to_a()
click to toggle source
# File lib/hoss/util/lru_cache.rb, line 49 def to_a @data.to_a end
Private Instance Methods
add(key, val)
click to toggle source
# File lib/hoss/util/lru_cache.rb, line 55 def add(key, val) @data.delete(key) @data[key] = val return unless @data.length > @max_size @data.delete(@data.first[0]) end