aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/cache.rb
diff options
context:
space:
mode:
authorAlexey Gaziev <alex.gaziev@gmail.com>2011-12-27 10:54:05 +0800
committerAlexey Gaziev <alex.gaziev@gmail.com>2011-12-27 10:54:05 +0800
commitf7b1906ed784940bda6f0c5173036de276867c1c (patch)
tree7f438b7fcd84af96d202139e47764a45bcc30b42 /activesupport/lib/active_support/cache.rb
parentd7cfb636367f2f929d07ade9060d35a2cf7ad20b (diff)
downloadrails-f7b1906ed784940bda6f0c5173036de276867c1c.tar.gz
rails-f7b1906ed784940bda6f0c5173036de276867c1c.tar.bz2
rails-f7b1906ed784940bda6f0c5173036de276867c1c.zip
Safe getting value from cache entry
Diffstat (limited to 'activesupport/lib/active_support/cache.rb')
-rw-r--r--activesupport/lib/active_support/cache.rb12
1 files changed, 11 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb
index 7d032ca984..6ba0a600b1 100644
--- a/activesupport/lib/active_support/cache.rb
+++ b/activesupport/lib/active_support/cache.rb
@@ -578,7 +578,17 @@ module ActiveSupport
# it is marshalled and eventually compressed. Both operations yield
# strings.
if @value
- Marshal.load(compressed? ? Zlib::Inflate.inflate(@value) : @value)
+ # In rails 3.1 and earlier values in entries did not marshaled without
+ # options[:compress] and if it's Numeric.
+ # But after commit a263f377978fc07515b42808ebc1f7894fafaa3a
+ # all values in entries are marshalled. And after that code below expects
+ # that all values in entries will be marshaled (and will be strings).
+ # So here we need a check for old ones.
+ begin
+ Marshal.load(compressed? ? Zlib::Inflate.inflate(@value) : @value)
+ rescue
+ compressed? ? Zlib::Inflate.inflate(@value) : @value
+ end
end
end