Class: Cuboid::Support::Cache::LeastCostReplacement
- Defined in:
- lib/cuboid/support/cache/least_cost_replacement.rb
Overview
Least Cost Replacement cache implementation.
Maintains 3 cost classes (low, medium, high) ) and discards entries from the lowest cost classes in order to make room for new ones.
Constant Summary collapse
- VALID_COSTS =
[ :low, :medium, :high ]
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #clear ⇒ Object
-
#initialize ⇒ LeastCostReplacement
constructor
A new instance of LeastCostReplacement.
-
#store(k, v, cost = :low) ⇒ Object
Storage method.
Methods inherited from Base
#==, #[], #[]=, #any?, #capped?, #delete, #dup, #empty?, #fetch, #hash, #include?, #size, #statistics, #uncap, #uncapped?
Methods included from Mixins::Profiler
disable!, enable!, included, on?, #profile_proc, #profile_wrap_proc, results
Constructor Details
#initialize ⇒ LeastCostReplacement
Returns a new instance of LeastCostReplacement.
15 16 17 18 |
# File 'lib/cuboid/support/cache/least_cost_replacement.rb', line 15 def initialize( * ) super reset_costs end |
Instance Method Details
#clear ⇒ Object
40 41 42 43 44 |
# File 'lib/cuboid/support/cache/least_cost_replacement.rb', line 40 def clear super ensure reset_costs end |
#store(k, v, cost = :low) ⇒ Object
Storage method
31 32 33 34 35 36 37 |
# File 'lib/cuboid/support/cache/least_cost_replacement.rb', line 31 def store( k, v, cost = :low ) fail( "invalid cost: #{cost}" ) if !valid_cost?( cost ) super( k, v ) ensure @costs[cost] << k end |