class Dry::Effects::Providers::Cache

Attributes

cache[R]

Public Instance Methods

call(cache = EMPTY_HASH.dup) { || ... } click to toggle source

Yield the block with the handler installed

@api private

# File lib/dry/effects/providers/cache.rb, line 27
def call(cache = EMPTY_HASH.dup)
  @cache = cache
  yield
end
fetch_or_store(key, block) click to toggle source
# File lib/dry/effects/providers/cache.rb, line 16
def fetch_or_store(key, block)
  if cache.key?(key)
    cache[key]
  else
    Instructions.Execute { cache[key] = block.call }
  end
end
provide?(effect) click to toggle source

@param [Effect] effect @return [Boolean] @api public

Calls superclass method
# File lib/dry/effects/providers/cache.rb, line 35
def provide?(effect)
  super && scope.eql?(effect.scope)
end
represent() click to toggle source

@return [String] @api public

# File lib/dry/effects/providers/cache.rb, line 41
def represent
  if cache.empty?
    "cache[#{scope} empty]"
  else
    "cache[#{scope} size=#{cache.size}]"
  end
end