class Looksist::SafeLruCache
Public Class Methods
new(max_size)
click to toggle source
Calls superclass method
# File lib/looksist/safe_lru_cache.rb, line 8 def initialize(max_size) @max_size = max_size super(nil) end
Private Class Methods
synchronize(*methods)
click to toggle source
Calls superclass method
# File lib/looksist/safe_lru_cache.rb, line 41 def self.synchronize(*methods) methods.each do |method| define_method method do |*args, &blk| synchronize do super(*args, &blk) end end end end
Public Instance Methods
[]=(key, val)
click to toggle source
Calls superclass method
# File lib/looksist/safe_lru_cache.rb, line 13 def []=(key, val) synchronize do super(key, val) pop val end end
merge!(hash)
click to toggle source
Calls superclass method
# File lib/looksist/safe_lru_cache.rb, line 21 def merge!(hash) synchronize do super(hash) (count - @max_size).times { pop } end end
mslice(keys)
click to toggle source
# File lib/looksist/safe_lru_cache.rb, line 28 def mslice(keys) synchronize do keys.collect { |k| self[k] } end end
Private Instance Methods
pop()
click to toggle source
# File lib/looksist/safe_lru_cache.rb, line 36 def pop # not using shift coz: http://bugs.ruby-lang.org/issues/8312 delete(first[0]) if count > @max_size end