What is the best Rails caching option for largely

2019-07-08 20:20发布

I have a set of largely static pages which I'd be happy to page cache for relatively long periods apart from the fact that their layout includes a much more dynamic header.

The most promising idea so far seems to be using action caching without layout :-

class SomethingController < ApplicationController

  caches_action :index, :layout => false

end

Then at least the main content of the page is cached. Does that make sense?

Or would I be better off doing something else, e.g. fragment caching, server-side include, etc...?

1条回答
啃猪蹄的小仙女
2楼-- · 2019-07-08 20:32

What I have done is use page caching, and then make an AJAX call to fetch either:

  1. The entire header.
  2. Specific parts of the header that are dynamic.

Also, if you are just looking to include the users name, a better way exists. Simply store their name in a cookie and then use javascript to display it in the header. With no cookie, show a link to go login or register.

查看更多
登录 后发表回答