Skip to content
Browse files

caching 'false' properly

  • Loading branch information...
1 parent 3df6c73 commit cd392fd4da08d1d3b73fa66e945594b89d5f75de @vijaydev vijaydev committed Nov 14, 2011
Showing with 7 additions and 2 deletions.
  1. +2 −2 activesupport/lib/active_support/cache.rb
  2. +5 −0 activesupport/test/caching_test.rb
View
4 activesupport/lib/active_support/cache.rb
@@ -555,7 +555,7 @@ def initialize(value, options = {})
@expires_in = options[:expires_in]
@expires_in = @expires_in.to_f if @expires_in
@created_at = Time.now.to_f
- if value
+ unless value.nil?
if should_compress?(value, options)
@value = Zlib::Deflate.deflate(Marshal.dump(value))
@compressed = true
@@ -574,7 +574,7 @@ def raw_value
# Get the value stored in the cache.
def value
- if @value
+ unless @value.nil?
val = compressed? ? Marshal.load(Zlib::Inflate.inflate(@value)) : @value
unless val.frozen?
val.freeze rescue nil
View
5 activesupport/test/caching_test.rb
@@ -188,6 +188,11 @@ def test_should_read_and_write_nil
assert_equal nil, @cache.read('foo')
end
+ def test_should_read_and_write_false
+ assert_equal true, @cache.write('foo', false)
+ assert_equal false, @cache.read('foo')
+ end
+
def test_read_multi
@cache.write('foo', 'bar')
@cache.write('fu', 'baz')

0 comments on commit cd392fd

Please sign in to comment.
Something went wrong with that request. Please try again.