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 | |
parent | 9cd094b8da492b711002dd4b1f2792f315e9bde0 (diff) | |
download | rails-254ab7d916e579b9300951f5f33d3c5d3ee755a2.tar.gz rails-254ab7d916e579b9300951f5f33d3c5d3ee755a2.tar.bz2 rails-254ab7d916e579b9300951f5f33d3c5d3ee755a2.zip |
First pass at Rack::Cache
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/actionpack.gemspec | 20 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/http/rack_cache.rb | 67 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/railtie.rb | 1 |
3 files changed, 79 insertions, 9 deletions
diff --git a/actionpack/actionpack.gemspec b/actionpack/actionpack.gemspec index 5b219540f4..75ac47105d 100644 --- a/actionpack/actionpack.gemspec +++ b/actionpack/actionpack.gemspec @@ -19,13 +19,15 @@ Gem::Specification.new do |s| s.has_rdoc = true - s.add_dependency('activesupport', version) - s.add_dependency('activemodel', version) - s.add_dependency('builder', '~> 2.1.2') - s.add_dependency('i18n', '~> 0.4.1') - s.add_dependency('rack', '~> 1.2.1') - s.add_dependency('rack-test', '~> 0.5.4') - s.add_dependency('rack-mount', '~> 0.6.13') - s.add_dependency('tzinfo', '~> 0.3.23') - s.add_dependency('erubis', '~> 2.6.6') + s.add_dependency('activesupport', version) + s.add_dependency('activemodel', version) + s.add_dependency('rack-cache', '~> 0.5.2') + s.add_dependency('rack-cache-purge', '~> 0.0.1') + s.add_dependency('builder', '~> 2.1.2') + s.add_dependency('i18n', '~> 0.4.1') + s.add_dependency('rack', '~> 1.2.1') + s.add_dependency('rack-test', '~> 0.5.4') + s.add_dependency('rack-mount', '~> 0.6.13') + s.add_dependency('tzinfo', '~> 0.3.23') + s.add_dependency('erubis', '~> 2.6.6') end 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 |