aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2011-05-17 17:32:52 -0400
committerJosé Valim <jose.valim@gmail.com>2011-05-17 17:33:17 -0400
commit324f1451b06c82242426b1a239b0559181b16c37 (patch)
treeddcee1d830ad340319764ffd1c2abfbb9606d81d
parentb77e032ccf50249685c672c2d75f173db2ee2dbf (diff)
downloadrails-324f1451b06c82242426b1a239b0559181b16c37.tar.gz
rails-324f1451b06c82242426b1a239b0559181b16c37.tar.bz2
rails-324f1451b06c82242426b1a239b0559181b16c37.zip
Dump and load rack-cache stuff.
-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