Class: Looksist::SafeLruCache
- Includes:
- MonitorMixin
- Defined in:
- lib/looksist/safe_lru_cache.rb
Instance Method Summary collapse
- #[]=(key, val) ⇒ Object
-
#initialize(max_size) ⇒ SafeLruCache
constructor
A new instance of SafeLruCache.
- #merge!(hash) ⇒ Object
- #mslice(keys) ⇒ Object
Methods inherited from Hash
Constructor Details
#initialize(max_size) ⇒ SafeLruCache
Returns a new instance of SafeLruCache.
8 9 10 11 |
# File 'lib/looksist/safe_lru_cache.rb', line 8 def initialize(max_size) @max_size = max_size super(nil) end |
Instance Method Details
#[]=(key, val) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/looksist/safe_lru_cache.rb', line 13 def []=(key, val) synchronize do super(key, val) pop val end end |
#merge!(hash) ⇒ Object
21 22 23 24 25 26 |
# 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) ⇒ Object
28 29 30 31 32 |
# File 'lib/looksist/safe_lru_cache.rb', line 28 def mslice(keys) synchronize do keys.collect { |k| self[k] } end end |