Permalink
Browse files

Dump and load rack-cache stuff.

  • Loading branch information...
1 parent b77e032 commit 324f1451b06c82242426b1a239b0559181b16c37 @josevalim josevalim committed May 17, 2011
Showing with 27 additions and 2 deletions.
  1. +6 −2 actionpack/lib/action_dispatch/http/rack_cache.rb
  2. +21 −0 actionpack/test/dispatch/rack_cache_test.rb
@@ -14,11 +14,15 @@ def initialize(store = RAILS_CACHE)
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
@@ -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

0 comments on commit 324f145

Please sign in to comment.