ruby - How does fragment & ActiveRecord or SQL caching work in Rails 4? -


alright, have basic cms in works & liked try hand @ caching set of dynamically generated navigation links. in pages_controller, have following action toggle page's visibility, query create @nav_links variable based on pages visible

before_filter :nav_links, only: [:index, :new, :show, :edit]  def toggle   @visibility = @page.visible? ? false : true   unless @page.update_attribute(:visible, @visibility)     flash[:alert] = "uh oh! looks went wrong."   end   expire_fragment "nav" end  def nav_links   @nav_links = {}   groups = pagegroup.order("id")   groups.each |group|     if group.visible?       @nav_links[group.name.to_sym] = group.pages.where(visible: true)     end   end end 

in view, i've wrapped section of page pertaining @nav_links <% cache "nav" %>...<% end %>. question, happens when 1 of these actions called?

  1. does rails still execute before_filter, query database, & re-populate @nav_links hash per visit? or called if view can't find copy of @nav_links in cache? if doesn't execute each time, rails use sql caching default use same results unless record changed?

  2. do need modify nav_links method or cache work expected changes view & action updates page's visibility?

thanks in advanced; i'm new @ rails hope questions make sense.

if have cache "nav" wrapped around template code, code run once, results cached, , cache reused until template changes. cache invocation doesn't reference data objects, there no application state can change result in cache being busted.

also, i'm expire_fragment doesn't work rails 4 cache digests.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -