Flowdock
method

write

Importance_2
Ruby on Rails latest stable (v3.2.13) - 1 note - Class: ActiveSupport::Cache::MemCacheStore

Method deprecated or moved

This method is deprecated or moved on the latest stable version. The last existing version (v2.3.8) is shown here.

These similar methods exist in v3.2.13:

write(key, value, options = nil) public

Writes a value to the cache.

Possible options:

  • :unless_exist - set to true if you don’t want to update the cache if the key is already set.
  • :expires_in - the number of seconds that this value may stay in the cache. See ActiveSupport::Cache::Store#write for an example.
Show source
Register or log in to add new notes.
October 2, 2008
1 thank

Setting ttl

Use the expires_in option to set a TTL for the cached item.

Rails.cache.write("top_items", :expires_in => 5.minutes)

You can use this with the fetch method as well:

Rails.cache.fetch("top_items", :expires_in => 5.minutes) do
  # some very expensive calculations
end

Note: this only works with supporting cache stores, like the MemCacheStore