Rails页面缓存不起作用,动作缓存抛出“过滤器链暂停" [英] Rails Page Caching not working and Action Caching throwing 'Filter Chain Halted'

查看:66
本文介绍了Rails页面缓存不起作用,动作缓存抛出“过滤器链暂停"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

设置


Controller -> Action Index 
  results = Model.all (SQL Call)

View
  Loop through and render partial from results.  Call count for result row  (SQL Call)

Partial 
  Manage result data and add point on Google map  

我正尝试缓存此页面,因此我向控制器添加了 caches_page:index .当我查看此页面时,它将创建成功的模板缓存(但不是部分缓存).但是,它仍然使所有不应调用的sql调用.

I'm attempting to cache this page so I add caches_page :index to my controller. When I view this page it creates a successful cache of the template (but not the partial). However it still makes all of the sql calls it shouldn't.

通过更改 caches_action:index ,不会进行任何SQL调用,但是我收到两个过滤器链停止"错误.

By changing it caches_action :index no sql calls are made, but I receive two 'Filter chain halted' errors.

页面正确呈现,所以我不知道这是我应该注意还是不应该看的东西.

The page renders correctly so I don't know if this is something I should look over or not.

如果任何人都能够解释为什么caches_page无法正常工作,或者我应该从此处停止Filter链的位置,我将不胜感激.

If anyone is able to explain why caches_page isn't working, or where I should go from here on the Filter chain halted, I would greatly appreciate it.

谢谢!

推荐答案

首先,如果要在开发环境中测试缓存,请确保设置:

Firstly, if you want to test caching in the development environment, make sure you set:

# in config/environments/development.rb
config.action_controller.perform_caching = true

第二,页面缓存的工作原理是将静态HTML文件写入与您的缓存操作相同的URL的/public目录.收到请求时,您的Web服务器将看到静态文件并提供该文件,从而完全避免了Rails.图像的投放方式相同.如果更改 config.action_controller.page_cache_directory ,您的静态文件将被写入错误的目录/URL,并且Web服务器不会注意到该文件.

Secondly, page caching works by writing a static HTML file to your /public directory with the same URL as the action you are caching. When a request comes in, your web server sees the static file and serves it, avoiding Rails entirely. It's the same way images are served. If you change config.action_controller.page_cache_directory your static files will be written to the wrong directory/URL and not noticed by the web server.

最后,如果对生成静态文件的缓存操作进行了更改,请确保删除生成的静态文件,否​​则修改后的操作将不会运行.即使禁用缓存也是如此!您仍然需要删除文件.

Lastly, make sure to delete the generated static files if you make changes to the cached actions that produce them, otherwise the modified actions will not be run. This is true even if you disable caching! You still need to delete the files.

这篇关于Rails页面缓存不起作用,动作缓存抛出“过滤器链暂停"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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