Module: Merb::Cache::ControllerInstanceMethods

Module | Merb::Cache::ControllerInstanceMethods
In: | lib/merb-cache/cache-action.rb lib/merb-cache/cache-fragment.rb lib/merb-cache/cache-page.rb lib/merb-cache/merb-cache.rb

### Methods

abort_cache_action abort_cache_page cache cache_get cache_set cached? cached_action? cached_page? expire expire_action expire_all expire_all_pages expire_page

### Constants

DEFAULT_PAGE_EXTENSION | = | 'html' |  | Mixed in Merb::Controller. Provides methods related to page caching

### Public Instance methods

abort_cache_action()

You can call this method if you need to prevent caching the action after it has been rendered.

abort_cache_page()

You can call this method if you need to prevent caching the page after it has been rendered.

cache(options, from_now = nil, &block)

#### Example

      In your view:
      <%- cache("my_key") do -%>
        <%= partial :test, :collection => @test %>
      <%- end -%>

cache_get(options)

Fetch data from cache

#### Parameter

options<String,Hash>: | The options that will be passed to key_for

#### Returns

data<Object,NilClass>: | nil is returned if the cache entry is not found

#### Example

      if cache_data = cache_get("my_key")
        @var1, @var2 = *cache_data
      else
        @var1 = MyModel.big_query1
        @var2 = MyModel.big_query2
        cache_set("my_key", nil, [@var1, @var2])
      end

cache_set(options, object, from_now = nil)

Store data to cache

#### Parameter

options<String,Hash>: | The options that will be passed to key_for
object<Object>: | The object(s) to put in cache
from_now<~minutes>: | The number of minutes (from now) the cache should persist

#### Returns

data<Object,NilClass>: | nil is returned if the cache entry is not found

#### Example

      if cache_data = cache_get("my_key")
        @var1, @var2 = *cache_data
      else
        @var1 = MyModel.big_query1
        @var2 = MyModel.big_query2
        cache_set("my_key", nil, [@var1, @var2])
      end

cached?(options)

Checks whether a cache entry exists

#### Parameter

options<String,Hash>: | The options that will be passed to key_for

#### Returns

true if the cache entry exists, false otherwise

#### Example

      cached_action?("my_key")

cached_action?(options)

Checks whether a cache entry exists

#### Parameter

options<String,Hash>: | The options that will be passed to key_for

#### Returns

true if the cache entry exists, false otherwise

#### Example

      cached_action?(:action => 'show', :params => [params[:page]])

cached_page?(options)

Checks whether a cache entry exists

#### Parameter

options<String,Hash>: | The options that will be passed to key_for

#### Returns

true if the cache entry exists, false otherwise

#### Example

      cached_page?(:action => 'show', :params => [params[:page]])
      cached_page?(:action => 'show', :extension => 'js')

expire(options)

Expires the entry identified by the key computed after the parameters

#### Parameter

options<String,Hash>: | The options that will be passed to key_for

#### Examples

      expire("my_key")
      expire(:key => "my_", :match => true)
      expire(:key => "my_key", :params => [session[:me], params[:ref]])

expire_action(options)

Expires the action identified by the key computed after the parameters

#### Parameter

options<String,Hash>: | The options that will be passed to expire_key_for

#### Examples

      expire_action(:action => 'show', :controller => 'news')
      expire_action(:action => 'show', :match => true)

expire_all()

Mixed in Merb::Controller and provides expire_all for action and fragment caching.

expire_all_pages()

Expires all the pages stored in config[:cache_html_directory]

expire_page(options)

Expires the page identified by the key computed after the parameters

#### Parameter

options<String,Hash>: | The options that will be passed to expire_key_for

#### Examples

      expire_page(:action => 'show', :controller => 'news')
      expire_page(:action => 'show', :match => true)
      expire_page(:action => 'show', :extension => 'js')

[Validate]