Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 858
matsko Avatar asked Jan 20 '26 17:01

matsko


1 Answers

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 %>
like image 189
Anatoly Avatar answered Jan 23 '26 06:01

Anatoly



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!