提交 ff29606c 编写于 作者: C Carlhuda

Refactor cache_store to use ActionController config

上级 c8e1cc86
......@@ -40,15 +40,27 @@ module Caching
autoload :Sweeping, 'action_controller/caching/sweeping'
end
included do
@@cache_store = nil
cattr_reader :cache_store
module ConfigMethods
def cache_store
config.cache_store
end
# Defines the storage option for cached fragments
def self.cache_store=(store_option)
@@cache_store = ActiveSupport::Cache.lookup_store(store_option)
def cache_store=(store)
config.cache_store = ActiveSupport::Cache.lookup_store(store)
end
private
def cache_configured?
perform_caching && cache_store
end
end
include ConfigMethods
included do
extend ConfigMethods
include Pages, Actions, Fragments
include Sweeping if defined?(ActiveRecord)
......@@ -56,11 +68,6 @@ def self.cache_store=(store_option)
cattr_accessor :perform_caching
end
module ClassMethods
def cache_configured?
perform_caching && cache_store
end
end
def caching_allowed?
request.get? && response.status == 200
......@@ -75,10 +82,5 @@ def cache(key, options = {}, &block)
yield
end
end
private
def cache_configured?
self.class.cache_configured?
end
end
end
......@@ -35,11 +35,6 @@ def rescue_action(env)
raise env["action_dispatch.rescue.exception"]
end
# Defines the storage option for cached fragments
def cache_store=(store_option)
@@cache_store = ActiveSupport::Cache.lookup_store(store_option)
end
self.page_cache_directory = defined?(Rails.public_path) ? Rails.public_path : ""
end
......
......@@ -6,12 +6,18 @@
# Don't change '/../temp/' cavalierly or you might hose something you don't want hosed
FILE_STORE_PATH = File.join(File.dirname(__FILE__), '/../temp/', CACHE_DIR)
ActionController::Base.page_cache_directory = FILE_STORE_PATH
ActionController::Base.cache_store = :file_store, FILE_STORE_PATH
class PageCachingTestController < ActionController::Base
class CachingController < ActionController::Base
abstract!
self.cache_store = :file_store, FILE_STORE_PATH
end
class PageCachingTestController < CachingController
caches_page :ok, :no_content, :if => Proc.new { |c| !c.request.format.json? }
caches_page :found, :not_found
def ok
head :ok
end
......@@ -55,6 +61,7 @@ def setup
@response = ActionController::TestResponse.new
@controller = PageCachingTestController.new
@controller.cache_store = :file_store, FILE_STORE_PATH
@params = {:controller => 'posts', :action => 'index', :only_path => true, :skip_relative_url_root => true}
@rewriter = ActionController::UrlRewriter.new(@request, @params)
......@@ -148,7 +155,7 @@ def page_cached?(action)
end
end
class ActionCachingTestController < ActionController::Base
class ActionCachingTestController < CachingController
rescue_from(Exception) { head 500 }
if defined? ActiveRecord
rescue_from(ActiveRecord::RecordNotFound) { head :not_found }
......@@ -522,7 +529,7 @@ def read_fragment(path)
end
end
class FragmentCachingTestController < ActionController::Base
class FragmentCachingTestController < CachingController
def some_action; end;
end
......@@ -531,8 +538,8 @@ def setup
super
ActionController::Base.perform_caching = true
@store = ActiveSupport::Cache::MemoryStore.new
ActionController::Base.cache_store = @store
@controller = FragmentCachingTestController.new
@controller.cache_store = @store
@params = {:controller => 'posts', :action => 'index'}
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
......@@ -630,7 +637,7 @@ def test_fragment_for
end
class FunctionalCachingController < ActionController::Base
class FunctionalCachingController < CachingController
def fragment_cached
end
......@@ -664,8 +671,8 @@ def setup
super
ActionController::Base.perform_caching = true
@store = ActiveSupport::Cache::MemoryStore.new
ActionController::Base.cache_store = @store
@controller = FunctionalCachingController.new
@controller.cache_store = @store
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
end
......
......@@ -46,8 +46,7 @@ def setup
@cache_path = File.expand_path('../temp/test_cache', File.dirname(__FILE__))
ActionController::Base.page_cache_directory = @cache_path
ActionController::Base.cache_store = :file_store, @cache_path
@controller.cache_store = :file_store, @cache_path
Rails::LogSubscriber.add(:action_controller, ActionController::Railties::LogSubscriber.new)
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册