Class: CacheLib::FifoCache

Inherits:
BasicCache show all
Defined in:
lib/cache_lib/fifo_cache.rb

Direct Known Subclasses

SafeFifoCache

Instance Attribute Summary

Attributes inherited from BasicCache

#limit

Instance Method Summary collapse

Methods inherited from BasicCache

#clear, #each, #evict, #expire, #fetch, #get, #initialize_copy, #inspect, #key?, #keys, #lookup, #raw, #size, #store, #to_a, #values

Constructor Details

#initialize(*args) ⇒ FifoCache

Returns a new instance of FifoCache.



3
4
5
6
7
8
9
10
11
12
# File 'lib/cache_lib/fifo_cache.rb', line 3

def initialize(*args)
  limit, _ = args

  fail ArgumentError, "Cache Limit must be 1 or greater: #{limit}" if
      limit.nil? || limit < 1

  @limit = limit

  @cache = UtilHash.new
end

Instance Method Details

#limit=(args) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/cache_lib/fifo_cache.rb', line 14

def limit=(args)
  limit, _ = args

  limit ||= @limit

  fail ArgumentError, "Cache Limit must be 1 or greater: #{limit}" if
      limit.nil? || limit < 1

  @limit = limit

  resize
end