Rails 5 缓存控制在 heroku 中不起作用

Rails 5 cache control doesn't work in heroku

我正在我的应用程序中设置 CDN,并根据 Rails 中的新标准设置 cache-control 5:

config.public_file_server.headers = {
    'Cache-Control' => 'public, max-age = 31536000',
    'Expires' => "# {1.year.from_now.to_formatted_s (: rfc822)}"
}

但是当我将应用程序部署到 Heroku 时,它表明我没有使用新标准:

DEPRECATION WARNING: config.static_cache_control is deprecated and will be removed in Rails 5.1. Please use config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=604800' } instead. (called from at /app/config/application.rb:14)

并且当我查看页面响应时 headers 未应用 cache-control 设置

散列值之间的逗号只是在这个问题中缺失,还是在您的配置中也缺失?试试这个:

config.public_file_server.headers = {
  'Cache-Control' => 'public, max-age = 31536000',
  'Expires' => "# {1.year.from_now.to_formatted_s (: rfc822)}"
}

我找到了这个问题的解决方案 https://github.com/romanbsd/heroku-deflater/issues/26,问题出在 gem heroku deflater