开发者

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

开发者 https://www.devze.com 2023-03-29 13:34 出处:网络
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中文版

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

精彩评论

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