Module: Knuckles::Stages::Writer

Extended by:
Writer
Included in:
Writer
Defined in:
lib/knuckles/stages/writer.rb

Overview

After un-cached models have been serialized they are ready to be cached for future retrieval. Each fully serialized model is written to the cache in a single ‘write_multi` operation if available (using Readthis, for example). Only previously un-cached data will be written to the cache, making the writer a no-op when all of the data was cached initially.

Instance Method Summary collapse

Instance Method Details

#call(objects, _options) ⇒ Object

Write all serialized, but previously un-cached, data to the cache.

Parameters:

  • objects (Enumerable)

    A collection of hashes to be serialized, each hash must have they keys ‘:key`, `:result`, and `:cached?`.

  • _options (Hash)

    Options aren’t used, but are accepted to maintain a consistent interface

Returns:

  • The original enumerable is returned unchanged



21
22
23
24
25
26
27
28
29
# File 'lib/knuckles/stages/writer.rb', line 21

def call(objects, _options)
  if cache.respond_to?(:write_multi)
    write_multi(objects)
  else
    write_each(objects)
  end

  objects
end