我正在尝试在我的rails 4应用程序中实现缓存。我安装了redis,根据这个article设置配置,但每次我尝试在我的控制器中缓存一些东西,第一次刷新时我得到数据,第二次我得到零。当我访问redis cli时,我做了key *,我看到key就在那里。
我认为这是我的redis的问题,所以我禁用了redis,并在development.rb中放入
config.cache_store = :memory_store, { size: 128.megabytes }但如果我试着
Rails.cache.fetch("dashboard") do
User.where(:active=>true).size
end作为对我行为的回应,我得到了零。
我做错了什么,缓存总是返回nil?
编辑:这是我的redis development.rb文件的一部分
config.cache_store = :redis_store, {
expires_in: 1.hour,
namespace: 'cache',
redis: { host: 'localhost', port: 6379, db: 0 },
}发布于 2019-06-04 15:27:37
这没什么,但是缓存不会被存储。因此,您必须检查它的配置。例如。在环境文件中,您应该有以下代码片段:
config.action_controller.perform_caching = true
config.cache_store = :media_store:media_store -取决于您要存储缓存的位置。
https://stackoverflow.com/questions/56094787
复制相似问题