Class: Determinator::Cache::FetchWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/determinator/cache/fetch_wrapper.rb

Instance Method Summary collapse

Constructor Details

#initialize(*caches) ⇒ FetchWrapper

list should will be checked before the tail. If the head is empty but the tail is not then the head will be filled with the value of the tail.

Parameters:

  • *caches (ActiveSupport::Cache)

    If a list then the head of the the



7
8
9
# File 'lib/determinator/cache/fetch_wrapper.rb', line 7

def initialize(*caches)
  @caches = caches
end

Instance Method Details

#call(feature_name) ⇒ Object

Call walks through each cache, returning a value if the item exists in any cache, otherwise popularing each cache with the value of yield.



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/determinator/cache/fetch_wrapper.rb', line 13

def call(feature_name)
  value = read_and_upfill(feature_name)
  # nil is an acceptable value in the case of a missing feature definition
  return nil if value.nil?
  return value if value != false

  value_to_write = yield
  @caches.each do |cache|
    cache.write(key(feature_name), value_to_write)
  end
  return value_to_write
end

#expire(feature_name) ⇒ Object



26
27
28
# File 'lib/determinator/cache/fetch_wrapper.rb', line 26

def expire(feature_name)
  @caches.each{ |c| c.delete(key(feature_name)) }
end