Sunday, 15 March 2015

caching - What's the best way to cache static pages in Rails 4? -



caching - What's the best way to cache static pages in Rails 4? -

in order boost performance of rails 4.0.2 app, cache output of of static pages:

class pagescontroller < applicationcontroller def home end def about_us end def contact end end

in rails guide on caching says "page caching has been removed rails 4" , moved gem. in gem description says, however, maintained until rails 4.1. other observers advise against using page caching , endorse russian doll caching instead.

so what's best way cache bunch of static pages never nail database , ever alter (slightly) if user signs in?

thanks suggestions.

you can still using fragment caching static pages, although benefits more visible dynamic / db-driven pages. it's worth considering doing should have lot of partial beingness rendered or costly view logic. wrap page's template with:

# about_us.html.erb <% cache 'about_us' %> ... <% end %>

the first time nail page in environment config.action_controller.perform_caching = true, it'll generate fragment (which in case whole page), , it'll serve next time reload it. cache digest invalidated when template changed:

the template digest that's added cache key computed taking md5 of contents of entire template file. ensures caches automatically expire when alter template file.

http://api.rubyonrails.org/classes/actionview/helpers/cachehelper.html

ruby-on-rails caching ruby-on-rails-4

No comments:

Post a Comment