Class: Arachni::Cache::LeastCostReplacement

Inherits:
Base
  • Object
show all
Defined in:
lib/arachni/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.

Author:

Constant Summary collapse

VALID_COSTS =
[ :low, :medium, :high ]

Instance Attribute Summary

Attributes inherited from Base

#max_size

Instance Method Summary collapse

Methods inherited from Base

#[], #[]=, #any?, #capped?, #delete, #empty?, #fetch_or_store, #include?, #size, #uncap, #uncapped?

Constructor Details

#initializeLeastCostReplacement

Returns a new instance of LeastCostReplacement.

See Also:



30
31
32
33
# File 'lib/arachni/cache/least_cost_replacement.rb', line 30

def initialize( * )
    super
    reset_costs
end

Instance Method Details

#clearObject

See Also:



55
56
57
58
59
# File 'lib/arachni/cache/least_cost_replacement.rb', line 55

def clear
    super
ensure
    reset_costs
end

#store(k, v, cost = :low) ⇒ Object

Storage method

Parameters:

  • k (Object)

    entry key

  • v (Object)

    object to store

  • cost (Symbol) (defaults to: :low)

Returns:

See Also:



46
47
48
49
50
51
52
# File 'lib/arachni/cache/least_cost_replacement.rb', line 46

def store( k, v, cost = :low )
    fail( "invalid cost: #{cost}" ) if !valid_cost?( cost )

    super( k, v )
ensure
    @costs[cost] << k
end