Class: Arachni::Support::Cache::Base Abstract
- Defined in:
 - lib/arachni/support/cache/base.rb
 
Overview
Base cache implementation – stores, retrieves and removes entries.
The cache will be pruned (call #prune) upon storage operations, removing old entries to make room for new ones.
Direct Known Subclasses
LeastCostReplacement, LeastRecentlyPushed, Preference, RandomReplacement
Instance Attribute Summary collapse
- 
  
    
      #max_size  ⇒ Integer 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Maximum cache size.
 
Instance Method Summary collapse
- #==(other) ⇒ Object
 - 
  
    
      #[](k)  ⇒ Object? 
    
    
  
  
  
  
  
  
  
  
  
    
Retrieving method.
 - #[]=(k, v) ⇒ Object
 - 
  
    
      #any?  ⇒ Bool 
    
    
  
  
  
  
  
  
  
  
  
    
`true` if cache is not empty, `false` otherwise.
 - 
  
    
      #capped?  ⇒ Bool 
    
    
  
  
  
  
  
  
  
  
  
    
`true` is there is a size limit, `false“ otherwise.
 - 
  
    
      #clear  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Clears/empties the cache.
 - 
  
    
      #delete(k)  ⇒ Object? 
    
    
  
  
  
  
  
  
  
  
  
    
Removes entry with key `k` from the cache.
 - #dup ⇒ Object
 - 
  
    
      #empty?  ⇒ Bool 
    
    
  
  
  
  
  
  
  
  
  
    
`true` if cache is empty, false otherwise.
 - 
  
    
      #fetch(k, &block)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Value for key `k` or `block.call` if key `k` does not exist.
 - #hash ⇒ Object
 - 
  
    
      #include?(k)  ⇒ Bool 
    
    
  
  
  
  
  
  
  
  
  
    
`true` if cache includes an entry for key `k`, false otherwise.
 - 
  
    
      #initialize(max_size = nil)  ⇒ Base 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of Base.
 - 
  
    
      #size  ⇒ Integer 
    
    
  
  
  
  
  
  
  
  
  
    
Number of entries in the cache.
 - 
  
    
      #store(k, v)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Storage method.
 - 
  
    
      #uncap  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Uncaps the cache #max_size limit.
 - 
  
    
      #uncapped?  ⇒ Bool 
    
    
  
  
  
  
  
  
  
  
  
    
`true` is there is no size limit, `false` otherwise.
 
Constructor Details
#initialize(max_size = nil) ⇒ Base
Returns a new instance of Base.
      29 30 31 32  | 
    
      # File 'lib/arachni/support/cache/base.rb', line 29 def initialize( max_size = nil ) self.max_size = max_size @cache = {} end  | 
  
Instance Attribute Details
#max_size ⇒ Integer
Returns Maximum cache size.
      23 24 25  | 
    
      # File 'lib/arachni/support/cache/base.rb', line 23 def max_size @max_size end  | 
  
Instance Method Details
#==(other) ⇒ Object
      145 146 147  | 
    
      # File 'lib/arachni/support/cache/base.rb', line 145 def ==( other ) hash == other.hash end  | 
  
#[](k) ⇒ Object?
Retrieving method.
      90 91 92  | 
    
      # File 'lib/arachni/support/cache/base.rb', line 90 def []( k ) get_with_internal_key( make_key( k ) ) end  | 
  
#[]=(k, v) ⇒ Object
      79 80 81  | 
    
      # File 'lib/arachni/support/cache/base.rb', line 79 def []=( k, v ) store( k, v ) end  | 
  
#any? ⇒ Bool
Returns `true` if cache is not empty, `false` otherwise.
      125 126 127  | 
    
      # File 'lib/arachni/support/cache/base.rb', line 125 def any? !empty? end  | 
  
#capped? ⇒ Bool
Returns `true` is there is a size limit, `false“ otherwise.
      51 52 53  | 
    
      # File 'lib/arachni/support/cache/base.rb', line 51 def capped? !!max_size end  | 
  
#clear ⇒ Object
Clears/empties the cache.
      141 142 143  | 
    
      # File 'lib/arachni/support/cache/base.rb', line 141 def clear @cache.clear end  | 
  
#delete(k) ⇒ Object?
Removes entry with key `k` from the cache.
      136 137 138  | 
    
      # File 'lib/arachni/support/cache/base.rb', line 136 def delete( k ) @cache.delete( make_key( k ) ) end  | 
  
#dup ⇒ Object
      153 154 155  | 
    
      # File 'lib/arachni/support/cache/base.rb', line 153 def dup deep_clone end  | 
  
#empty? ⇒ Bool
Returns `true` if cache is empty, false otherwise.
      119 120 121  | 
    
      # File 'lib/arachni/support/cache/base.rb', line 119 def empty? @cache.empty? end  | 
  
#fetch(k, &block) ⇒ Object
If key `k` exists, its corresponding value will be returned. If not, the return value of `block` will be assigned to key `k` and that value will be returned.
Returns Value for key `k` or `block.call` if key `k` does not exist.
      103 104 105 106 107 108 109  | 
    
      # File 'lib/arachni/support/cache/base.rb', line 103 def fetch( k, &block ) k = make_key( k ) @cache.include?( k ) ? get_with_internal_key( k ) : store_with_internal_key( k, block.call ) end  | 
  
#hash ⇒ Object
      149 150 151  | 
    
      # File 'lib/arachni/support/cache/base.rb', line 149 def hash @cache.hash end  | 
  
#include?(k) ⇒ Bool
Returns `true` if cache includes an entry for key `k`, false otherwise.
      113 114 115  | 
    
      # File 'lib/arachni/support/cache/base.rb', line 113 def include?( k ) @cache.include?( make_key( k ) ) end  | 
  
#size ⇒ Integer
Returns Number of entries in the cache.
      62 63 64  | 
    
      # File 'lib/arachni/support/cache/base.rb', line 62 def size @cache.size end  | 
  
#store(k, v) ⇒ Object
Storage method.
      74 75 76  | 
    
      # File 'lib/arachni/support/cache/base.rb', line 74 def store( k, v ) store_with_internal_key( make_key( k ), v ) end  | 
  
#uncap ⇒ Object
Uncaps the cache #max_size limit
      56 57 58  | 
    
      # File 'lib/arachni/support/cache/base.rb', line 56 def uncap @max_size = nil end  | 
  
#uncapped? ⇒ Bool
Returns `true` is there is no size limit, `false` otherwise.
      45 46 47  | 
    
      # File 'lib/arachni/support/cache/base.rb', line 45 def uncapped? !capped? end  |