Class: Determinator::Cache::FetchWrapper
- Inherits:
-
Object
- Object
- Determinator::Cache::FetchWrapper
- Defined in:
- lib/determinator/cache/fetch_wrapper.rb
Instance Method Summary collapse
-
#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.
- #expire(feature_name) ⇒ Object
-
#initialize(*caches, cache_missing: true) ⇒ FetchWrapper
constructor
list should will be checked before the tail.
Constructor Details
#initialize(*caches, cache_missing: true) ⇒ 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.
7 8 9 10 |
# File 'lib/determinator/cache/fetch_wrapper.rb', line 7 def initialize(*caches, cache_missing: true) @cache_missing = cache_missing @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.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/determinator/cache/fetch_wrapper.rb', line 14 def call(feature_name) value = read_and_upfill(feature_name) # if the value is missing and we cache it, return the missing response return value if value.is_a?(MissingResponse) && @cache_missing #otherwise only return the non nil/notice_missing_feature value return value if !value.nil? && !(value.is_a?(MissingResponse) && !@cache_missing) value_to_write = yield return value_to_write if value_to_write.is_a?(ErrorResponse) @caches.each do |cache| cache.write(key(feature_name), value_to_write) end return value_to_write end |
#expire(feature_name) ⇒ Object
31 32 33 |
# File 'lib/determinator/cache/fetch_wrapper.rb', line 31 def expire(feature_name) @caches.each{ |c| c.delete(key(feature_name)) } end |