提交 edd33c08 编写于 作者: R Robin Clowers

Fix Cache#fetch instrumentation

Before this change, you couldn't tell if a read was a hit or not when
you called fetch.
上级 a948490b
......@@ -277,13 +277,18 @@ def fetch(name, options = nil)
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 @@ def log
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册