lib/active_support/cache.rb in activesupport-7.1.1 vs lib/active_support/cache.rb in activesupport-7.1.2

- old
+ new

@@ -457,11 +457,21 @@ entry = nil unless options[:force] instrument(:read, name, options) do |payload| cached_entry = read_entry(key, **options, event: payload) entry = handle_expired_entry(cached_entry, key, options) - entry = nil if entry && entry.mismatched?(normalize_version(name, options)) + if entry + if entry.mismatched?(normalize_version(name, options)) + entry = nil + else + begin + entry.value + rescue DeserializationError + entry = nil + end + end + end payload[:super_operation] = :fetch if payload payload[:hit] = !!entry if payload end end @@ -509,11 +519,16 @@ elsif entry.mismatched?(version) payload[:hit] = false if payload nil else payload[:hit] = true if payload - entry.value + begin + entry.value + rescue DeserializationError + payload[:hit] = false + nil + end end else payload[:hit] = false if payload nil end @@ -1036,9 +1051,11 @@ instrument(:fetch_hit, name, options) entry.value end def save_block_result_to_cache(name, options) + options = options.dup + result = instrument(:generate, name, options) do yield(name, WriteOptions.new(options)) end write(name, result, options) unless result.nil? && options[:skip_nil]