提交 4f7ca00b 编写于 作者: S Santiago Pastorino

Merge pull request #2010 from hasclass/cache_false_values

Properly cache value when it is "false"
......@@ -557,7 +557,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
if defined?(value)
if should_compress?(value, options)
@value = Zlib::Deflate.deflate(Marshal.dump(value))
@compressed = true
......@@ -576,7 +576,7 @@ def raw_value
# Get the value stored in the cache.
def value
if @value
if defined?(@value)
val = compressed? ? Marshal.load(Zlib::Inflate.inflate(@value)) : @value
unless val.frozen?
val.freeze rescue nil
......
......@@ -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')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册