Module: Components::Caching::ClassMethods

Defined in:
lib/components/caching.rb

Instance Method Summary collapse

Instance Method Details

#cache(action, cache_options = nil) ⇒ Object

Caches the named actions by wrapping them via alias_method_chain. May only be called on actions (methods) that have already been defined.

Cache options will be passed through to the cache store’s read/write methods.



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/components/caching.rb', line 93

def cache(action, cache_options = nil)
  return unless ActionController::Base.cache_configured?

  class_eval <<-EOL, __FILE__, __LINE__
    cattr_accessor :#{action}_cache_options

    def #{action}_with_caching(*args)
      with_caching(:#{action}, args) do
        #{action}_without_caching(*args)
      end
    end
    alias_method_chain :#{action}, :caching
  EOL
  self.send("#{action}_cache_options=", cache_options)
end

#cache_storeObject

:nodoc:



109
110
111
# File 'lib/components/caching.rb', line 109

def cache_store #:nodoc:
  @cache_store ||= ActionController::Base.cache_store
end