Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Manually Clear Fragment Cache in Rails

Tags:

I'm using Memcached with Heroku for a Rails 3.1 app. I had a bug and the wrong things are showing - the parameters were incorrect for the cache.

I had this:

<% cache("foo_header_cache_#{@user.id}") do %>  

I removed the fragment caching and pushed to Heroku and the bad data went away.

And then I changed it to:

<% cache("foo_header_cache_#{@foo.id}") do %>  

However, when I corrected the parameters, from @user to @foo, the old [incorrect] cached version showed again (instead of refreshing with the correct data).

How can I manually expire this, or otherwise get rid of this bad data that is showing?

like image 446
yellowreign Avatar asked May 04 '12 06:05

yellowreign


People also ask

How do I flush Rails cache?

clear in the Rails console to clear the cache. Unfortunately there is no way (yet) to do it from the command line. We can add a rake task that will do this for us. Then we can execute ./bin/rake cache:clear and clear the Rails cache from the command line.

Where is Rails cache stored?

By default, the page cache directory is set to Rails. public_path (which is usually set to the public folder) and this can be configured by changing the configuration setting config. action_controller. page_cache_directory.

How do you cache objects in Rails?

In order to use page and action caching you will need to add actionpack-page_caching and actionpack-action_caching to your Gemfile . By default, caching is only enabled in your production environment. You can play around with caching locally by running rails dev:cache , or by setting config. action_controller.

What is Russian doll caching?

Ruby on Rails Caching Russian Doll Caching You may want to nest cached fragments inside other cached fragments. This is called Russian doll caching . The advantage of Russian doll caching is that if a single product is updated, all the other inner fragments can be reused when regenerating the outer fragment.


1 Answers

I ended up manually clearing the entire cache by going into the rails console and using the command:

Rails.cache.clear 
like image 198
yellowreign Avatar answered Sep 28 '22 02:09

yellowreign