aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/http/rack_cache.rb
diff options
context:
space:
mode:
authorwycats <wycats@gmail.com>2010-09-13 14:03:06 -0700
committerCarlhuda <carlhuda@engineyard.com>2010-09-13 16:06:03 -0700
commit254ab7d916e579b9300951f5f33d3c5d3ee755a2 (patch)
tree722bb7e82ecdcef9bac2383e766c0a7fb398c6d1 /actionpack/lib/action_dispatch/http/rack_cache.rb
parent9cd094b8da492b711002dd4b1f2792f315e9bde0 (diff)
downloadrails-254ab7d916e579b9300951f5f33d3c5d3ee755a2.tar.gz
rails-254ab7d916e579b9300951f5f33d3c5d3ee755a2.tar.bz2
rails-254ab7d916e579b9300951f5f33d3c5d3ee755a2.zip
First pass at Rack::Cache
Diffstat (limited to 'actionpack/lib/action_dispatch/http/rack_cache.rb')
-rw-r--r--actionpack/lib/action_dispatch/http/rack_cache.rb67
1 files changed, 67 insertions, 0 deletions
diff --git a/actionpack/lib/action_dispatch/http/rack_cache.rb b/actionpack/lib/action_dispatch/http/rack_cache.rb
new file mode 100644
index 0000000000..e5914abc81
--- /dev/null
+++ b/actionpack/lib/action_dispatch/http/rack_cache.rb
@@ -0,0 +1,67 @@
+require "rack/cache"
+require "rack/cache/context"
+require "active_support/cache"
+
+module ActionDispatch
+ class RailsMetaStore < Rack::Cache::MetaStore
+ def self.resolve(uri)
+ new
+ end
+
+ # TODO: Finally deal with the RAILS_CACHE global
+ def initialize(store = RAILS_CACHE)
+ @store = store
+ end
+
+ def read(key)
+ @store.read(key) || []
+ end
+
+ def write(key, value)
+ @store.write(key, value)
+ end
+
+ def purge(key)
+ @store.delete(key)
+ nil
+ end
+
+ ::Rack::Cache::MetaStore::RAILS = self
+ end
+
+ class RailsEntityStore < Rack::Cache::EntityStore
+ def self.resolve(uri)
+ new
+ end
+
+ def initialize(store = RAILS_CACHE)
+ @store = store
+ end
+
+ def exist?(key)
+ @store.exist?(key)
+ end
+
+ def open(key)
+ @store.read(key)
+ end
+
+ def read(key)
+ body = open(key)
+ body.join if body
+ end
+
+ def write(body)
+ buf = []
+ key, size = slurp(body) { |part| buf << part }
+ @store.write(key, buf)
+ [key, size]
+ end
+
+ def purge(key)
+ @store.delete(key)
+ end
+
+ ::Rack::Cache::EntityStore::RAILS = self
+ end
+end