aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSantiago Pastorino <santiago@wyeworks.com>2011-10-29 19:18:46 -0700
committerSantiago Pastorino <santiago@wyeworks.com>2011-10-29 19:18:46 -0700
commit75ee4d97ef68dc3be22bd68102030f495cbc8d4a (patch)
tree56d7974cd8e0f386bf2dd8a2633bdf768cd31388
parent11f6795b238172c4a13176062bd38b83285799b7 (diff)
parent3b546afd049221fd4aa407d6b99f1c4de312c704 (diff)
downloadrails-75ee4d97ef68dc3be22bd68102030f495cbc8d4a.tar.gz
rails-75ee4d97ef68dc3be22bd68102030f495cbc8d4a.tar.bz2
rails-75ee4d97ef68dc3be22bd68102030f495cbc8d4a.zip
Merge pull request #3464 from kennyj/avoid_to_call_twice
avoided to call `Marshal.dump` twice
-rw-r--r--activesupport/lib/active_support/cache.rb13
1 files changed, 5 insertions, 8 deletions
diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb
index 8aefda858d..8b45efaf2a 100644
--- a/activesupport/lib/active_support/cache.rb
+++ b/activesupport/lib/active_support/cache.rb
@@ -559,7 +559,7 @@ module ActiveSupport
@value = nil
else
@value = Marshal.dump(value)
- if should_compress?(value, options)
+ if should_compress?(@value, options)
@value = Zlib::Deflate.deflate(@value)
@compressed = true
end
@@ -613,13 +613,10 @@ module ActiveSupport
end
private
- def should_compress?(value, options)
- if options[:compress] && value
- unless value.is_a?(Numeric)
- compress_threshold = options[:compress_threshold] || DEFAULT_COMPRESS_LIMIT
- serialized_value = value.is_a?(String) ? value : Marshal.dump(value)
- return true if serialized_value.size >= compress_threshold
- end
+ def should_compress?(serialized_value, options)
+ if options[:compress]
+ compress_threshold = options[:compress_threshold] || DEFAULT_COMPRESS_LIMIT
+ return true if serialized_value.size >= compress_threshold
end
false
end