使用Memcached进行页面缓存 [英] Page Caching with Memcached

查看:180
本文介绍了使用Memcached进行页面缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Ruby on Rails 3应用程序中使用Memcached.它非常适合操作和片段缓存,但是当我尝试使用页面缓存时,页面存储在文件系统中,而不是存储在Memcached中.如何告诉Rails也使用Memcached进行页面缓存?

I am using Memcached in my Ruby on Rails 3 app. It works great with action and fragment caching, but when I try to use page caching, the page is stored in the filesystem instead of in Memcached. How can I tell Rails to use Memcached for page caching too?

在我的development.rb文件中:

In my development.rb file:

config.action_controller.perform_caching = true
config.cache_store = :mem_cache_store

推荐答案

您不能. memcached中的页面缓存等效于操作缓存,因为该请求必须通过Rails提供.页面缓存旨在绕过Rails,因此数据必须存储在可以从服务器提供服务的文件中,例如Nginx或Apache.页面缓存之所以如此之快是因为它确实完全绕过了Rails.这是Rails文档所说的:

You cant. The equivalent of page caching in memcached is action caching, because the request must be served through Rails. Page caching is meant to bypass Rails, so the data must be stored in a file that can be served from the server, like Nginx or Apache. The reason page caching is so fast is that it does bypass Rails entirely. Here is what the Rails documentation says:

页面缓存是一种Rails机制 允许请求 生成的页面要由 网络服务器(即apache或nginx), 无需经历 Rails堆栈都没有.显然,这是 超级快.不幸的是,不可能 适用于各种情况(例如 需要身份验证的页面)和 因为网络服务器实际上只是 提供文件系统中的文件, 缓存过期是一个问题 需要处理.

Page caching is a Rails mechanism which allows the request for a generated page to be fulfilled by the webserver (i.e. apache or nginx), without ever having to go through the Rails stack at all. Obviously, this is super-fast. Unfortunately, it can’t be applied to every situation (such as pages that need authentication) and since the webserver is literally just serving a file from the filesystem, cache expiration is an issue that needs to be dealt with.

您可以在此处找到更多信息.

You can find more information here.

这篇关于使用Memcached进行页面缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆