method
write
v2.2.1 -
Show latest stable
-
1 note -
Class: ActiveSupport::Cache::MemCacheStore
- 1.0.0
- 1.1.0
- 1.1.1
- 1.1.6
- 1.2.0
- 1.2.6
- 2.0.0
- 2.0.1
- 2.0.3
- 2.1.0 (0)
- 2.2.1 (23)
- 2.3.2 (0)
- 2.3.8 (0)
- 3.0.0
- 3.0.5
- 3.0.7
- 3.0.9
- 3.1.0
- 3.2.1
- 3.2.3
- 3.2.8
- 3.2.13
- What's this?
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 <a href="/rails/ActiveSupport/Cache/Store/write">ActiveSupport::Cache::Store#write</a> for an example.
Register or
log in
to add new notes.
LacKac -
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


