lib/active_support/cache.rb in activesupport-6.0.3.7 vs lib/active_support/cache.rb in activesupport-6.0.4
- old
+ new
@@ -310,11 +310,11 @@
# cache = ActiveSupport::Cache::MemCacheStore.new
# cache.fetch("foo", force: true, raw: true) do
# :bar
# end
# cache.fetch('foo') # => "bar"
- def fetch(name, options = nil)
+ def fetch(name, options = nil, &block)
if block_given?
options = merged_options(options)
key = normalize_key(name, options)
entry = nil
@@ -325,13 +325,13 @@
payload[:super_operation] = :fetch if payload
payload[:hit] = !!entry if payload
end
if entry
- get_entry_value(entry, name, **options)
+ get_entry_value(entry, name, options)
else
- save_block_result_to_cache(name, **options) { |_name| yield _name }
+ save_block_result_to_cache(name, options, &block)
end
elsif options && options[:force]
raise ArgumentError, "Missing block: Calling `Cache#fetch` with `force: true` requires a block."
else
read(name, options)
@@ -446,11 +446,11 @@
end
payload[:hits] = reads.keys
payload[:super_operation] = :fetch_multi
- write_multi(writes, **options)
+ write_multi(writes, options)
ordered
end
end
@@ -710,10 +710,10 @@
def get_entry_value(entry, name, options)
instrument(:fetch_hit, name, options) { }
entry.value
end
- def save_block_result_to_cache(name, **options)
+ def save_block_result_to_cache(name, options)
result = instrument(:generate, name, options) do
yield(name)
end
write(name, result, options) unless result.nil? && options[:skip_nil]