具有页面内管理功能的 Rails 页面缓存
我很想在我运行的 Rails 站点上使用页面缓存。每个页面上的信息大多是恒定的,但是需要运行来收集信息的查询很复杂,并且在某些情况下可能很慢。使用页面缓存的唯一障碍是管理界面内置于主站点中,因此无需离开感兴趣的页面即可执行管理操作。
我正在使用 Apache+mod_rails(乘客)。有没有办法向 Apache 指示当当前用户具有会话变量或名为“admin”* 的 cookie 时应忽略 .html 文件? Apache 不需要评估会话变量的有效性(因为在本例中它将由 Rails 评估)。
I'd love to use page caching on a Rails site I run. The information on each page is mostly constant, but the queries that need to be run to collect the information are complicated and can be slow in some cases.The only obstacle to using page caching is that the administrative interface is built into the main site so that admin operations can be performed without leaving the page of interest.
I'm using Apache+mod_rails (Passenger). Is there a way to indicate to Apache that .html files should be ignored when the current user either has a session variable or a cookie named 'admin'*? The session variable need not be evaluated by Apache for validity (since it will be evaluated by Rails in this case).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信这实际上是不可能的。即使是这样,我想也应该非常棘手。
相反,您可以使用操作缓存。文档中的引用:
这听起来正是你的情况。
但如果您仍然确实需要通过网络服务器进行页面缓存,我认为您最好为管理员和非管理员实现单独的页面。
这是因为一个原因。当您启用页面缓存时,rails 根本不处理请求,因此无法知道用户是否经过身份验证。
您可能可以使用动态页面缓存来克服这个问题。这个想法基本上是从 JavaScript 添加“admin”部分。不过我个人不太喜欢这个。
另一项更新:快速搜索将我带到< a href="http://blog.carldr.com/73/dead-good-caching" rel="nofollow noreferrer">这篇文章。
这个想法是有条件地缓存页面并插入
mod_rewrite
来服务管理页面。将为你工作,但这是一个非常肮脏的解决方案。
I believe it is not really possible. Even if it is, I guess should be very tricky.
Instead you can use Action Caching. A quote from docs:
This sounds like exactly your case.
But if you still really need Page Caching via web server, I think you better implement separate pages for admin and non-admin.
This is because of one reason. When you enable Page Caching rails doesn't process the request at all and thus there is no way to know if user is authenticated or not.
You probably can overcome this using Dynamic Page Caching. The idea is basically to add the "admin" part from the JavaScript. I don't personally like this a lot though.
One more update: quick search brought me to this article.
The idea is to cache page conditionally and plug
mod_rewrite
to serve admin pages.Will work for you but is pretty dirty solution.