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

Constants

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

Public Instance methods

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

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

Example

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

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

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

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")

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]])

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')

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]])

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)

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

Expires all the pages stored in config[:cache_html_directory]

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]