使用 Memcached 进行页面缓存
我在 Ruby on Rails 3 应用程序中使用 Memcached。它非常适合操作和片段缓存,但当我尝试使用页面缓存时,页面存储在文件系统中而不是 Memcached 中。我如何告诉 Rails 使用 Memcached 进行页面缓存?
在我的development.rb 文件中:
config.action_controller.perform_caching = true
config.cache_store = :mem_cache_store
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?
In my development.rb file:
config.action_controller.perform_caching = true
config.cache_store = :mem_cache_store
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你不能。 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:
You can find more information here.
检查这个:
http://globaldev.co.uk/2012/06/serving_memcached_pages_from_nginx/< /a >
简单地说,安装“memcaches_page”gem(将其添加到GemFile然后捆绑),然后将caches_page指令更改为memcaches_page,然后配置Nginx在访问应用程序之前为页面memcached服务器提供服务(在文章中描述)。
check this :
http://globaldev.co.uk/2012/06/serving_memcached_pages_from_nginx/
Cutting it shortly, install "memcaches_page" gem (add it to GemFile then bundle), then change caches_page directive to memcaches_page, then configure Nginx to serve page memcached server before hitting the application (described in the article) .