Skip to content

Commit cc50791

Browse files
committed
AS::Cache#fetch fully skip the read operation when force: true
It makes little sense to emit a `:read` event given we explictly asked not to read.
1 parent f04074c commit cc50791

File tree

1 file changed

+8
-6
lines changed
  • activesupport/lib/active_support

1 file changed

+8
-6
lines changed

activesupport/lib/active_support/cache.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -362,12 +362,14 @@ def fetch(name, options = nil, &block)
362362
key = normalize_key(name, options)
363363

364364
entry = nil
365-
instrument(:read, name, options) do |payload|
366-
cached_entry = read_entry(key, **options, event: payload) unless options[:force]
367-
entry = handle_expired_entry(cached_entry, key, options)
368-
entry = nil if entry && entry.mismatched?(normalize_version(name, options))
369-
payload[:super_operation] = :fetch if payload
370-
payload[:hit] = !!entry if payload
365+
unless options[:force]
366+
instrument(:read, name, options) do |payload|
367+
cached_entry = read_entry(key, **options, event: payload)
368+
entry = handle_expired_entry(cached_entry, key, options)
369+
entry = nil if entry && entry.mismatched?(normalize_version(name, options))
370+
payload[:super_operation] = :fetch if payload
371+
payload[:hit] = !!entry if payload
372+
end
371373
end
372374

373375
if entry

0 commit comments

Comments
 (0)