Method: Merb::Cache::ControllerInstanceMethods#cache_set

Defined in:
lib/merb-cache/cache-fragment.rb

#cache_set(options, object, from_now = nil) ⇒ Object

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


71
72
73
74
# File 'lib/merb-cache/cache-fragment.rb', line 71

def cache_set(options, object, from_now = nil)
  key = Merb::Controller._cache.key_for(options, controller_name)
  Merb::Controller._cache.store.cache_set(key, object, from_now)
end