def fetch(name, options = nil)
if block_given?
options = merged_options(options)
key = namespaced_key(name, options)
unless options[:force]
entry = instrument(:read, name, options) do |payload|
payload[:super_operation] = :fetch if payload
read_entry(key, options)
end
end
if entry && entry.expired?
race_ttl = options[:race_condition_ttl].to_f
if race_ttl and Time.now.to_f - entry.expires_at <= race_ttl
entry.expires_at = Time.now + race_ttl
write_entry(key, entry, :expires_in => race_ttl * 2)
else
delete_entry(key, options)
end
entry = nil
end
if entry
instrument(:fetch_hit, name, options) { |payload| }
entry.value
else
result = instrument(:generate, name, options) do |payload|
yield
end
write(name, result, options)
result
end
else
read(name, options)
end
end