diff options
author | wycats <wycats@gmail.com> | 2010-09-13 14:03:06 -0700 |
---|---|---|
committer | Carlhuda <carlhuda@engineyard.com> | 2010-09-13 16:06:03 -0700 |
commit | 254ab7d916e579b9300951f5f33d3c5d3ee755a2 (patch) | |
tree | 722bb7e82ecdcef9bac2383e766c0a7fb398c6d1 /actionpack/lib/action_dispatch | |
parent | 9cd094b8da492b711002dd4b1f2792f315e9bde0 (diff) | |
download | rails-254ab7d916e579b9300951f5f33d3c5d3ee755a2.tar.gz rails-254ab7d916e579b9300951f5f33d3c5d3ee755a2.tar.bz2 rails-254ab7d916e579b9300951f5f33d3c5d3ee755a2.zip |
First pass at Rack::Cache
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r-- | actionpack/lib/action_dispatch/http/rack_cache.rb | 67 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/railtie.rb | 1 |
2 files changed, 68 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 diff --git a/actionpack/lib/action_dispatch/railtie.rb b/actionpack/lib/action_dispatch/railtie.rb index 69537be876..0a3bd5fe40 100644 --- a/actionpack/lib/action_dispatch/railtie.rb +++ b/actionpack/lib/action_dispatch/railtie.rb @@ -9,6 +9,7 @@ module ActionDispatch config.action_dispatch.show_exceptions = true config.action_dispatch.best_standards_support = true config.action_dispatch.tld_length = 1 + config.action_dispatch.rack_cache = {:metastore => "rails:/", :entitystore => "rails:/", :verbose => true} initializer "action_dispatch.configure" do |app| ActionDispatch::Http::URL.tld_length = app.config.action_dispatch.tld_length |