5 require 'action_controller/caching/pages'
6 require 'action_controller/caching/actions'
7 require 'action_controller/caching/sql_cache'
8 require 'action_controller/caching/sweeping'
9 require 'action_controller/caching/fragments'
12 module ActionController
#:nodoc:
13 # Caching is a cheap way of speeding up slow applications by keeping the result of calculations, renderings, and database calls
14 # around for subsequent requests. Action Controller affords you three approaches in varying levels of granularity: Page, Action, Fragment.
16 # You can read more about each approach and the sweeping assistance by clicking the modules below.
18 # Note: To turn off all caching and sweeping, set Base.perform_caching = false.
23 # All the caching stores from ActiveSupport::Cache is available to be used as backends for Action Controller caching. This setting only
24 # affects action and fragment caching as page caching is always written to disk.
26 # Configuration examples (MemoryStore is the default):
28 # ActionController::Base.cache_store = :memory_store
29 # ActionController::Base.cache_store = :file_store, "/path/to/cache/directory"
30 # ActionController::Base.cache_store = :drb_store, "druby://localhost:9192"
31 # ActionController::Base.cache_store = :mem_cache_store, "localhost"
32 # ActionController::Base.cache_store = MyOwnStore.new("parameter")
34 def self.included(base
) #:nodoc:
37 cattr_reader
:cache_store
39 # Defines the storage option for cached fragments
40 def self.cache_store
=(store_option
)
41 @
@cache_store = ActiveSupport
::Cache.lookup_store(store_option
)
44 include Pages
, Actions
, Fragments
45 include Sweeping
, SqlCache
if defined?(ActiveRecord
)
47 @
@perform_caching = true
48 cattr_accessor
:perform_caching
50 def self.cache_configured
?
51 perform_caching
&& cache_store
57 # Convenience accessor
58 def cache(key
, options
= {}, &block
)
60 cache_store
.fetch(ActiveSupport
::Cache.expand_cache_key(key
, :controller), options
, &block
)
69 self.class.cache_configured
?