ruby-on-rails – Heroku Cedar Stack – 机架缓存标头
发布时间:2020-12-16 19:08:16 所属栏目:百科 来源:网络整理
导读:我无法想象我的生活.尝试使用Rack :: Cache来缓存Heroku上的一些静态公共页面,以及在它通过反向代理时执行操作缓存. 例如,这是我的“home”动作中的代码: class StaticPagesController ApplicationController layout 'public' caches_action :about,:contac
我无法想象我的生活.尝试使用Rack :: Cache来缓存Heroku上的一些静态公共页面,以及在它通过反向代理时执行操作缓存.
例如,这是我的“home”动作中的代码: class StaticPagesController < ApplicationController layout 'public' caches_action :about,:contact,......,:home,..... ...... def home last_modified = File.mtime("#{Rails.root}/app/views/static_pages/home.html.haml") fresh_when last_modified: last_modified,public: true,etag: last_modified expires_in 10.seconds,:public => true end 对于所有意图和目的,这应该有一个公共缓存控制标记,max-age 10 no? $curl -I http://myapp-staging.herokuapp.com/ HTTP/1.1 200 OK Cache-Control: max-age=0,private,must-revalidate Content-Type: text/html; charset=utf-8 Date: Thu,24 May 2012 06:50:45 GMT Etag: "997dacac05aa4c73f5a6861c9f5a9db0" Status: 200 OK Vary: Accept-Encoding X-Rack-Cache: stale,invalid X-Request-Id: 078d86423f234da1ac41b418825618c2 X-Runtime: 0.005902 X-Ua-Compatible: IE=Edge,chrome=1 Connection: keep-alive 我做错了什么吗?我觉得有一些陈旧的,无效的缓存响应…这是我第四次点击页面. 配置信息: # Use a different cache store in production config.cache_store = :dalli_store config.action_dispatch.rack_cache = { :verbose => true,:metastore => "memcached://#{ENV['MEMCACHE_SERVERS']}",:entitystore => "memcached://#{ENV['MEMCACHE_SERVERS']}"#,} # OLD : Disable Rails's static asset server (Apache or nginx will already do this) config.serve_static_assets = true config.static_cache_control = "public,max-age=2592000" (也许有一种方法可以手动设置缓存控制标头?看起来应该有一种更简单的方法). UPDATE 我甚至尝试将控制器操作降至最低限度: def home expires_in 10.seconds,:public => true #last_modified = File.mtime("#{Rails.root}/app/views/static_pages/home.html.haml") #fresh_when last_modified: last_modified,etag: last_modified end 它不起作用……
解决方法
也许重新考虑整个事情,只使用rails缓存.新的cache_digests gem应该让你在rails级别做你想做的事情变得微不足道:
https://github.com/rails/cache_digests 我愿意打赌这会打败你的方法,包括进行文件系统调用,每隔10秒检查一次文件时间戳. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |