matsko
matsko

Reputation: 22203

Possible way to detect if an action is being cached in Rails?

Using Rails 3, is it possible to detect to see inside of the layout or a before_filter to see if an action is going to be cached and if there is a cache hit for that action?

caches_index :something, :layout => false

So for example (inside application.html.erb)

<%= yield %>
<% @is_cached == ... %>

Is it possible to do it before and/or after yield call to the item?

Upvotes: 3

Views: 188

Answers (1)

Anatoly
Anatoly

Reputation: 15530

I'm using fragment caching this way:

  #helper
  def cache_unless(condition, name = {}, &block)
    unless condition
      cache(name, &block)
    else
      yield
    end
  end


  #view
  <% cache_unless has_permission?, :action => :index, :folder => @folder, :user_id => @user.id do %>
  ...
  <% end %>

Upvotes: 2

Related Questions