From a263f377978fc07515b42808ebc1f7894fafaa3a Mon Sep 17 00:00:00 2001 From: Brian Durand Date: Fri, 29 Jul 2011 17:27:45 -0500 Subject: Change ActiveSupport::Cache behavior to always return duplicate objects instead of frozen objects. --- activesupport/lib/active_support/cache.rb | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb index ac88c82709..2d2264e58a 100644 --- a/activesupport/lib/active_support/cache.rb +++ b/activesupport/lib/active_support/cache.rb @@ -557,15 +557,14 @@ module ActiveSupport @expires_in = options[:expires_in] @expires_in = @expires_in.to_f if @expires_in @created_at = Time.now.to_f - if defined?(value) + if value.nil? + @value = nil + else + @value = Marshal.dump(value) if should_compress?(value, options) - @value = Zlib::Deflate.deflate(Marshal.dump(value)) + @value = Zlib::Deflate.deflate(@value) @compressed = true - else - @value = value end - else - @value = nil end end @@ -576,12 +575,8 @@ module ActiveSupport # Get the value stored in the cache. def value - if defined?(@value) - val = compressed? ? Marshal.load(Zlib::Inflate.inflate(@value)) : @value - unless val.frozen? - val.freeze rescue nil - end - val + if @value + Marshal.load(compressed? ? Zlib::Inflate.inflate(@value) : @value) end end @@ -614,10 +609,8 @@ module ActiveSupport def size if @value.nil? 0 - elsif @value.respond_to?(:bytesize) - @value.bytesize else - Marshal.dump(@value).bytesize + @value.bytesize end end -- cgit v1.2.3