aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/lib/action_dispatch/http/rack_cache.rb8
-rw-r--r--actionpack/test/dispatch/rack_cache_test.rb21
2 files changed, 27 insertions, 2 deletions
diff --git a/actionpack/lib/action_dispatch/http/rack_cache.rb b/actionpack/lib/action_dispatch/http/rack_cache.rb
index b5c1435903..cc8edee300 100644
--- a/actionpack/lib/action_dispatch/http/rack_cache.rb
+++ b/actionpack/lib/action_dispatch/http/rack_cache.rb
@@ -14,11 +14,15 @@ module ActionDispatch
end
def read(key)
- @store.read(key) || []
+ if data = @store.read(key)
+ Marshal.load(data)
+ else
+ []
+ end
end
def write(key, value)
- @store.write(key, value)
+ @store.write(key, Marshal.dump(value))
end
::Rack::Cache::MetaStore::RAILS = self
diff --git a/actionpack/test/dispatch/rack_cache_test.rb b/actionpack/test/dispatch/rack_cache_test.rb
new file mode 100644
index 0000000000..79d8a64d29
--- /dev/null
+++ b/actionpack/test/dispatch/rack_cache_test.rb
@@ -0,0 +1,21 @@
+require 'abstract_unit'
+require 'action_dispatch/http/rack_cache'
+
+class RackCacheMetaStoreTest < ActiveSupport::TestCase
+ class ReadWriteHash < ::Hash
+ alias :read :[]
+ alias :write :[]=
+ end
+
+ setup do
+ @store = ActionDispatch::RailsMetaStore.new(ReadWriteHash.new)
+ end
+
+ test "stuff is deep duped" do
+ @store.write(:foo, { :bar => :original })
+ hash = @store.read(:foo)
+ hash[:bar] = :changed
+ hash = @store.read(:foo)
+ assert_equal :original, hash[:bar]
+ end
+end