开发者

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?开发者_StackOverflow中文版

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?


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 %>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜