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:

  • hash (Hash)

    Key value hash to write

  • options (Hash) (defaults to: {})

    Optional overrides



319
320
321
322
323
324
325
326
327
# File 'lib/readthis/cache.rb', line 319

def write_multi(hash, options = {})
  options = merged_options(options)

  invoke(:write_multi, hash.keys) do |store|
    store.multi do
      hash.each { |key, value| write_entity(key, value, store, options) }
    end
  end
end