Method: Readthis::Cache#write_multi

Defined in:
lib/readthis/cache.rb

#write_multi(hash, options = {}) ⇒ Object

Write multiple key value pairs simultaneously. This is an atomic operation that will always succeed and will overwrite existing values.

This is a non-standard, but useful, cache method.

Examples:


cache.write_multi('a', 1, 'b', 2) # => true

Parameters:

  • Key (Hash)

    value hash to write

  • Optional (Hash)

    overrides



241
242
243
244
245
246
247
248
249
250
251
# File 'lib/readthis/cache.rb', line 241

def write_multi(hash, options = {})
  options = merged_options(options)
  values  = hash.each_with_object([]) do |(key, value), memo|
    memo << namespaced_key(key, options)
    memo << entity.dump(value)
  end

  invoke(:write_multi, values) do |store|
    store.mset(values)
  end
end