开发者

Rails Page Caching not working and Action Caching throwing 'Filter Chain Halted'

setup

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

View
  Loop through and render partial from results.  Cal开发者_C百科l count for result row  (SQL Call)

Partial 
  Manage result data and add point on Google map  

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.

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.

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.

Thanks!


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

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜