Module: Knuckles::Stages::Fetcher

Extended by:
Fetcher
Included in:
Fetcher
Defined in:
lib/knuckles/stages/fetcher.rb

Overview

The fetcher is responsible for bulk retrieval of data from the cache. Fetching is done using a single ‘read_multi` operation, which is multiplexed in caches like Redis or MemCached.

The underlying cache must support ‘read_multi` for the stage to work.

Instance Method Summary collapse

Instance Method Details

#call(prepared, options) ⇒ Object

Fetch all previously cached objects from the configured store.

Examples:

Provide a custom keygen


keygen = Module.new do
  def self.expand_key(object)
    object.name
  end
end

Knuckles::Stages::Fetcher.call(prepared, keygen: keygen)

Use a lambda as a keygen


Knuckles::Stages::Fetcher.call(
  prepared,
  keygen: -> (object) { object.name }
)

Parameters:

  • prepared (Enumerable)

    The prepared collection to fetch

  • [Module] (Hash)

    a customizable set of options



37
38
39
40
41
42
43
44
# File 'lib/knuckles/stages/fetcher.rb', line 37

def call(prepared, options)
  results = get_cached(prepared, options)

  prepared.each do |hash|
    hash[:result] = results[hash[:key]]
    hash[:cached?] = !hash[:result].nil?
  end
end