【发布时间】:2013-05-17 10:26:39
【问题描述】:
我想在 Heroku 上的 Rails 应用中启用动作缓存。
在development.rb我设置:
config.action_controller.perform_caching = true
在日志中查看
Started GET "..." for 127.0.0.1 at 2013-05-17 14:03:25 +0400
...
Write fragment ...
OR
Read fragment ... (0.2ms)
->
为了转移到生产环境,我通过 $heroku addons:add memcache 安装了 memcache 插件,在 Gemfile 中安装了新的 gem:gem 'dalli',并在 production.rb 中更改了设置:
config.action_controller.perform_caching = true
config.cache_store = :dalli_store #, ENV['MEMCACHE_SERVERS'], { :namespace => 'myapp', :expires_in => 1.day, :compress => true }
我也尝试启用这两个注释参数,但无论如何我没有在日志中看到 Read/Write fragment ... 片段,我看到应用程序已通过身份验证,但缓存总是丢失
Started GET "..." for 195.178.108.38 at 2013-05-17 09:54:19 +0000
Dalli/SASL authenticating as myapp%40heroku.com
Dalli/SASL: Authenticated
cache: [GET ...] miss
运行$heroku run console我检查缓存是否正在加载:
irb(main):001:0> Rails.cache.read('color')
Dalli/SASL authenticating as myapp%40heroku.com
Dalli/SASL: Authenticated
=> nil
irb(main):002:0> Rails.cache.write('color', 'red')
=> true
irb(main):003:0> Rails.cache.read('color')
=> "red"
为什么动作缓存不起作用?
【问题讨论】: