class ActiveSupport::Cache::Store

def fetch_multi(*names)

# => nil
cache.read("fizz")
sleep(6)
# => "buzz"
cache.read("fizz")
# => {"fizz"=>"buzz"}
end
"buzz"
cache.fetch_multi("fizz", expires_in: 5.seconds) do |key|

Options are passed to the underlying cache implementation. For example:

# "unknown_key" => "Fallback value for key: unknown_key" }
# => { "bim" => "bam",
end
"Fallback value for key: #{key}"
cache.fetch_multi("bim", "unknown_key") do |key|
cache.write("bim", "bam")

Returns a hash with the data for each of the names. For example:

not found, use #read_multi.
to the cache. If you do not want to write the cache when the cache is
Therefore, you need to pass a block that returns the data to be written
and the result will be written to the cache and returned.
the supplied block is called for each key for which there was no data,
the cache with the given keys, then that data is returned. Otherwise,
Fetches data from the cache, using the given keys. If there is data in
def fetch_multi(*names)
  raise ArgumentError, "Missing block: `Cache#fetch_multi` requires a block." unless block_given?
  options = names.extract_options!
  options = merged_options(options)
  instrument :read_multi, names, options do |payload|
    reads   = read_multi_entries(names, **options)
    writes  = {}
    ordered = names.index_with do |name|
      reads.fetch(name) { writes[name] = yield(name) }
    end
    payload[:hits] = reads.keys
    payload[:super_operation] = :fetch_multi
    write_multi(writes, options)
    ordered
  end
end