【问题标题】:Rails query caching is not workingRails 查询缓存不起作用
【发布时间】:2013-04-29 20:18:59
【问题描述】:

我使用 redis_store 缓存查询。在开发日志中我看不到缓存的查询,它再次访问数据库并获取记录,但在我的 redis 控制台中,我可以看到我用来缓存查询的键.我在rails控制台中测试了使用键读取查询。我可以获得缓存的查询。帮我解决这个问题。

在我的模型中

Category = Rails.cache.fetch("category") {Category.select(:foo).unique}

在redis中

redis 127.0.0.1:6379> KEYS *
"category"

在 Rails 控制台中

Rails.cache.read("category")

【问题讨论】:

    标签: ruby-on-rails ruby ruby-on-rails-3 caching


    【解决方案1】:

    暂时将此行添加到/config/environments/development.rb

    config.action_controller.perform_caching = true
    

    完成后别忘了删除它!

    【讨论】:

    • 是的,这已经是真的了。我在同一个应用程序中使用缓存操作,但它工作正常。
    【解决方案2】:

    您不应该在开发中缓存,所以@megas 说的是真的,您应该进行测试以检查缓存是否正常工作,并且在您的测试环境中您可以将您的 config.action_controller.perform_caching 更改为 true。

    【讨论】:

      猜你喜欢
      • 2023-03-15
      • 1970-01-01
      • 2013-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-15
      • 2016-11-18
      • 2017-08-03
      相关资源
      最近更新 更多