Flowdock
method

write

Importance_1
Ruby on Rails latest stable (v6.1.7.7) - 1 note - Class: ActiveSupport::Cache::MemCacheStore

Method not available on this version

This method is only available on newer versions. The first available version of the method is shown here.

write(key, value, options = nil) public

Set key = value. Pass :unless_exist => true if you don’t want to update the cache if the key is already set.

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