Rails缓存的默认到期时间是多少? [英] What is the default expiry time for Rails cache?

查看:131
本文介绍了Rails缓存的默认到期时间是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经进行了一些谷歌搜索,但是找不到该问题的答案。 Rails可以这样指定其缓存的过期时间:

I've done some googling and couldn't find the answer to this question. Rails allows to specify expiry times for its cache like that:

Rails.cache.fetch("my_var", :expires_in => 10.seconds)

但是如果我什么都不指定怎么办:

But what happens if I specify nothing:

Rails.cache.fetch("my_var")

它永不过期?有默认值吗?我该如何明确定义永不过期的东西?

It never expires? Is there a default value? How can I explicitly define something that never expires?

推荐答案

这实际上取决于您所使用的缓存存储。 Rails提供了几种,其中最受欢迎的一种是 Memcached 。 Memcached的主要功能之一是它自动使未使用的旧记录到期,因此您可以忽略:expire选项。

It really depends on which cache storage you're using. Rails provides several, one of them most popular is Memcached. One of key features of Memcached is that it automatically expires old unused records, so you can forget about :expire option.

其他Rails高速缓存存储(例如内存存储或Redis存储将保留)不会过期,除非您明确指定何时这样做。

Other Rails cache storages, like memory storage or redis storage will keep will not expire date unless you explicitly specify when to do that.

有关缓存密钥过期如何工作的更多信息在Rails中。

这篇关于Rails缓存的默认到期时间是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆