module Garner::Cache::Context

Public Instance Methods

garner(&block) click to toggle source

Instantiate a context-appropriate cache identity.

@example

garner.bind(current_user) do
  { count: current_user.logins.count }
end

@return [Garner::Cache::Identity] The cache identity.

# File lib/garner/cache/context.rb, line 24
def garner(&block)
  identity = Garner::Cache::Identity.new(self)
  Garner.config.context_key_strategies.each do |strategy|
    identity = strategy.apply(identity, self)
  end

  block_given? ? identity.fetch(&block) : identity
end