aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/cache.rb
diff options
context:
space:
mode:
authorRobin Clowers <robin.clowers@gmail.com>2015-08-30 18:13:08 -0700
committerRobin Clowers <robin.clowers@gmail.com>2015-09-14 20:08:51 -0700
commitedd33c08d98723ae9bb89cf7f019277117ed6414 (patch)
treec5e554249c726896faf8ebfe05538f70074dbc5f /activesupport/lib/active_support/cache.rb
parenta948490b9c9dc31afb3ece482fb6dafb76c34225 (diff)
downloadrails-edd33c08d98723ae9bb89cf7f019277117ed6414.tar.gz
rails-edd33c08d98723ae9bb89cf7f019277117ed6414.tar.bz2
rails-edd33c08d98723ae9bb89cf7f019277117ed6414.zip
Fix Cache#fetch instrumentation
Before this change, you couldn't tell if a read was a hit or not when you called fetch.
Diffstat (limited to 'activesupport/lib/active_support/cache.rb')
-rw-r--r--activesupport/lib/active_support/cache.rb24
1 files changed, 11 insertions, 13 deletions
diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb
index 8253a76383..3996f583c2 100644
--- a/activesupport/lib/active_support/cache.rb
+++ b/activesupport/lib/active_support/cache.rb
@@ -277,13 +277,18 @@ module ActiveSupport
options = merged_options(options)
key = namespaced_key(name, options)
- cached_entry = find_cached_entry(key, name, options) unless options[:force]
- entry = handle_expired_entry(cached_entry, key, options)
+ instrument(:read, name, options) do |payload|
+ cached_entry = read_entry(key, options) unless options[:force]
+ payload[:super_operation] = :fetch if payload
+ entry = handle_expired_entry(cached_entry, key, options)
- if entry
- get_entry_value(entry, name, options)
- else
- save_block_result_to_cache(name, options) { |_name| yield _name }
+ if entry
+ payload[:hit] = true if payload
+ get_entry_value(entry, name, options)
+ else
+ payload[:hit] = false if payload
+ save_block_result_to_cache(name, options) { |_name| yield _name }
+ end
end
else
read(name, options)
@@ -556,13 +561,6 @@ module ActiveSupport
logger.debug(yield)
end
- def find_cached_entry(key, name, options)
- instrument(:read, name, options) do |payload|
- payload[:super_operation] = :fetch if payload
- read_entry(key, options)
- end
- end
-
def handle_expired_entry(entry, key, options)
if entry && entry.expired?
race_ttl = options[:race_condition_ttl].to_i