method
write
v2.1.0 -
Show latest stable
-
1 note -
Class: ActiveSupport::Cache::MemCacheStore
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0 (0)
- 2.2.1 (23)
- 2.3.8 (0)
- 3.0.0
- 3.0.9
- 3.1.0
- 3.2.1
- 3.2.8
- 3.2.13
- 4.0.2
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1
- 5.1.7
- 5.2.3
- 6.0.0
- 6.1.3.1
- 6.1.7.7
- 7.0.0
- 7.1.3.2 (17)
- 7.1.3.4 (0)
- What's this?
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.
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