0

I'm wondering what the best practice is for caching static content like an about page. In this case there could not be an actual action if using a matcher like

match 'about' => 'home#about'

This entire page could be cached, except that the layout includes a header that is unique to the user session. So using :layout => false would work as everything in the action can be cached, just not the layout.

I've used

caches_action :about, :layout => false

in the HomeController but I'm not convinced it's actually caching as the server reports 'Rendered' and it consistently takes 300-400ms.

What is the typical way of caching this type of content?

Rabbott
  • 4,282
  • 1
  • 30
  • 53

1 Answers1

1

The problem for you is this part of your question: except that the layout includes a header that is unique to the user session.

You could cache the whole page on a per user base. But that would mean that the page has to be rendered once per user and has to be stored on the harddrive. Depending on your use case it could make sense.

But in 9 out of 10 cases you want to just fragment cache the non changing part by:

<% cache('about_main') do %>

[...]

<% end %>

Have a look at http://xyzpub.com/en/ruby-on-rails/3.2/caching.html for a detailed view off the different kind of caches.

wintermeyer
  • 8,178
  • 8
  • 39
  • 85