Permalink
Browse files

MemcacheStore: deserialize the entry reading from local_cache when us…

…ing raw
  • Loading branch information...
1 parent 834bebf commit c2aacdf2eb833bc16b71530732bded1c8c7ef6f6 @sishen sishen committed Jun 9, 2011
Showing with 25 additions and 1 deletion.
  1. +8 −0 activesupport/lib/active_support/cache/mem_cache_store.rb
  2. +17 −1 activesupport/test/caching_test.rb
@@ -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
@@ -630,7 +630,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
@@ -639,6 +646,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

0 comments on commit c2aacdf

Please sign in to comment.