diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-09-13 08:31:32 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-09-13 08:31:32 +0000 |
commit | ebb7bd78351b7975f28fdcbadbbf0fe4804be2f2 (patch) | |
tree | 7be64a13212fce30d2ed351ed25d6ef3aeae9e59 /actionpack/lib/action_controller/caching.rb | |
parent | 48018bf4b5e5a2e173b4744abddc3e8cb590b4df (diff) | |
download | rails-ebb7bd78351b7975f28fdcbadbbf0fe4804be2f2.tar.gz rails-ebb7bd78351b7975f28fdcbadbbf0fe4804be2f2.tar.bz2 rails-ebb7bd78351b7975f28fdcbadbbf0fe4804be2f2.zip |
Added easy assignment of fragment cache store through use of symbols for included stores (old way still works too)
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2230 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_controller/caching.rb')
-rw-r--r-- | actionpack/lib/action_controller/caching.rb | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/actionpack/lib/action_controller/caching.rb b/actionpack/lib/action_controller/caching.rb index 095fb7f2f2..88529d8008 100644 --- a/actionpack/lib/action_controller/caching.rb +++ b/actionpack/lib/action_controller/caching.rb @@ -240,23 +240,28 @@ module ActionController #:nodoc: # # Configuration examples (MemoryStore is the default): # - # ActionController::Base.fragment_cache_store = - # ActionController::Caching::Fragments::MemoryStore.new - # - # ActionController::Base.fragment_cache_store = - # ActionController::Caching::Fragments::FileStore.new("/path/to/cache/directory") - # - # ActionController::Base.fragment_cache_store = - # ActionController::Caching::Fragments::DRbStore.new("druby://localhost:9192") - # - # ActionController::Base.fragment_cache_store = - # ActionController::Caching::Fragments::MemCacheStore.new("localhost") + # ActionController::Base.fragment_cache_store = :memory_store + # ActionController::Base.fragment_cache_store = :file_store, "/path/to/cache/directory" + # ActionController::Base.fragment_cache_store = :drb_store, "druby://localhost:9192" + # ActionController::Base.fragment_cache_store = :mem_cache_store, "localhost" + # ActionController::Base.fragment_cache_store = MyOwnStore.new("parameter") module Fragments def self.append_features(base) #:nodoc: super base.class_eval do @@fragment_cache_store = MemoryStore.new - cattr_accessor :fragment_cache_store + cattr_reader :fragment_cache_store + + def self.fragment_cache_store=(store_option) + store, *parameters = *([ store_option ].flatten) + @@fragment_cache_store = if store.is_a?(Symbol) + store_class_name = (store == :drb_store ? "DRbStore" : store.to_s.camelize) + store_class = ActionController::Caching::Fragments.const_get(store_class_name) + parameters.empty? ? store.new : store_class.new(*parameters) + else + store + end + end end end @@ -349,18 +354,26 @@ module ActionController #:nodoc: end class DRbStore < MemoryStore #:nodoc: + attr_reader :address + def initialize(address = 'druby://localhost:9192') + @address = address @data, @mutex = DRbObject.new(nil, address), Mutex.new end end class MemCacheStore < MemoryStore #:nodoc: + attr_reader :address + def initialize(address = 'localhost') + @address = address @data, @mutex = MemCache.new(address), Mutex.new end end class FileStore #:nodoc: + attr_reader :cache_path + def initialize(cache_path) @cache_path = cache_path end |