Skip to content

Commit

Permalink
Merge pull request #1608 from sishen/sishen
Browse files Browse the repository at this point in the history
MemcacheStore: deserialize the entry reading from local_cache when using
  • Loading branch information
josevalim committed Jul 11, 2011
2 parents e9f9ce9 + c2aacdf commit 8f2e321
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
8 changes: 8 additions & 0 deletions activesupport/lib/active_support/cache/mem_cache_store.rb
Expand Up @@ -183,6 +183,14 @@ def deserialize_entry(raw_value)
# Provide support for raw values in the local cache strategy.
module LocalCacheWithRaw # :nodoc:
protected
def read_entry(key, options)
entry = super
if options[:raw] && local_cache && entry
entry = deserialize_entry(entry.value)
end
entry
end

def write_entry(key, entry, options) # :nodoc:
retval = super
if options[:raw] && local_cache && retval
Expand Down
18 changes: 17 additions & 1 deletion activesupport/test/caching_test.rb
Expand Up @@ -635,7 +635,14 @@ def test_raw_values
cache.write("foo", 2)
assert_equal "2", cache.read("foo")
end


def test_raw_values_with_marshal
cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, :raw => true)
cache.clear
cache.write("foo", Marshal.dump([]))
assert_equal [], cache.read("foo")
end

def test_local_cache_raw_values
cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, :raw => true)
cache.clear
Expand All @@ -644,6 +651,15 @@ def test_local_cache_raw_values
assert_equal "2", cache.read("foo")
end
end

def test_local_cache_raw_values_with_marshal
cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, :raw => true)
cache.clear
cache.with_local_cache do
cache.write("foo", Marshal.dump([]))
assert_equal [], cache.read("foo")
end
end
end
end

Expand Down

0 comments on commit 8f2e321

Please sign in to comment.