method
write
![Moderate documentation Importance_2](https://d2vfyqvduarcvs.cloudfront.net/images/importance_2.png?1349367920)
v2.3.8 -
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
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.
Register or
log in
to add new notes.
LacKac -
October 2, 2008
![Default_avatar_30](https://www.gravatar.com/avatar/d3ab365ec2c78d27e5a68e912848e85f?default=http://apidock.com/images/default_avatar_30.png&size=30)
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