Reputation: 10014
I'm using caching in a rails app, but there are times where I'd like to be able to turn off caching for a specific request or regenerate the cached data (in production). I'd want to do this for debugging but also just to see what the performance difference is between the two.
Is there a way to turn off caching (with something like &cache=false) across the board without adding things like this throughout my code:
<% cache(x) unless params[:cache] == "false" do %>
Is there a way to tell rails to invalidate all of its cached elements as it renders the page, regenerating them? This would work, but again, I'd have to do it everywhere:
<% Rails.cache.delete <key> if params[:clear_cache] == "true" %>
or is there a good reason why I should just never do this.
Upvotes: 2
Views: 108
Reputation: 27747
You could always write that up as a method that you use instead of "cache"
def my_cache(x)
return x if params[:cache].blank? || params[:cache] == true
cache(x)
end
It'd be a little less messy in your views...
Alternatively, you might (I'm guessing) be able to play with ActionController::Base
's cacheing internals... but it'd be meta-hacking on rails' base code.
Upvotes: 1