gpt4 book ai didi

ruby-on-rails - Ruby on Rails 缓存 : Is it possible to increase the expiration time for a cache fragment during the execution time?

转载 作者:数据小太阳 更新时间:2023-10-29 08:54:21 28 4
gpt4 key购买 nike

我正在使用 Ruby on Rails 3,我想在执行期间增加缓存键的过期时间。我使用 memcached

比如我有

Rails.cache.write("key_test", "value_test", :expires_in => 10.seconds)

这样 key_test 将在 10 秒后过期。为了使该键值更长时间可用,我能做什么?是否可以仅增加 expires_in 而无需再次设置 value_test


下面的代码不起作用,但也许我必须做这样的事情:

Rails.cache.write("key_test", :expires_in => 10.seconds)

最佳答案

这会起作用:

Rails.cache.write('key_test', Rails.cache.read('key_test'), :expires_in => 10.seconds)

关于ruby-on-rails - Ruby on Rails 缓存 : Is it possible to increase the expiration time for a cache fragment during the execution time?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5180603/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com