Class: Cache::Strategy::LFU
- Inherits:
-
CapacityBounded
- Object
- Cache::Strategy
- CapacityBounded
- Cache::Strategy::LFU
- Defined in:
- lib/cache/cache.rb
Overview
Implements the least frequently used (LFU) strategy.
Defined Under Namespace
Classes: Item
Instance Attribute Summary
Attributes inherited from CapacityBounded
Instance Method Summary collapse
- #access(item) ⇒ Object
- #delete(item) ⇒ Object
-
#insert_or_extrude(item, enum) ⇒ Object
- enum
-
a [key, item] enumerable.
- #item_class ⇒ Object
Methods inherited from CapacityBounded
#dec, #empty?, #full?, #inc, #initialize
Constructor Details
This class inherits a constructor from Cache::Strategy::CapacityBounded
Instance Method Details
#access(item) ⇒ Object
60 61 62 |
# File 'lib/cache/cache.rb', line 60 def access(item) item.freq += 1 end |
#delete(item) ⇒ Object
64 65 66 |
# File 'lib/cache/cache.rb', line 64 def delete(item) dec(item) end |
#insert_or_extrude(item, enum) ⇒ Object
- enum
-
a [key, item] enumerable
71 72 73 74 75 76 |
# File 'lib/cache/cache.rb', line 71 def insert_or_extrude(item, enum) # find least recently used key/item and yield yield enum.min_by {|key, it| it.freq} while full? item.freq = 0 inc(item) end |
#item_class ⇒ Object
58 |
# File 'lib/cache/cache.rb', line 58 def item_class() Item end |