How to call expire_fragment in rails console

原创文章,转载请注明来源并保留原文链接

Today i want expire a fragment cache in my view.

<% cache('zires') do %>
  ...
<% end %>

So, i enter rails console – Rails c production, but i found Rails.cache.exist?('zires') return false.

Why?

Because your cache key is wrong! Check fragment_cache_key(key), rails adds a dynamic namespace – :views binding on key.

The easiest way:

ActionController::Base.new.expire_fragment('zires', options = nil)

Leave a Reply

Your email address will not be published. Required fields are marked *