[ruby-on-rails] Ruby on Rails: Clear a cached page

I have a RoR application (ruby v1.8.7; rails v2.3.5) that is caching a page in the development environment. This wouldn't be so much of an issue, but the cached page's a elements are incorrect.

I haven't made any changes to the development.rb file and I haven't knowingly added any caching commands to the controllers.

I've tried clearing the browser's (Firefox 3.5 on OSX) cookie and page caches for this site (localhost). I've also restarted Mongrel. Nothing seems to help.

What am I missing?

This question is related to ruby-on-rails caching

The answer is


I was able to resolve this problem by cleaning my assets cache:

$ rake assets:clean

If you're doing fragment caching, you can manually break the cache by updating your cache key, like so:

Version #1

<% cache ['cool_name_for_cache_key', 'v1'] do %>

Version #2

<% cache ['cool_name_for_cache_key', 'v2'] do %>

Or you can have the cache automatically reset based on the state of a non-static object, such as an ActiveRecord object, like so:

<% cache @user_object do %>

With this ^ method, any time the user object is updated, the cache will automatically be reset.


More esoteric ways:

Rails.cache.delete_matched("*")

For Redis:

Redis.new.keys.each{ |key| Rails.cache.delete(key) }

rake tmp:cache:clear might be what you're looking for.


Check for a static version of your page in /public and delete it if it's there. When Rails 3.x caches pages, it leaves a static version in your public folder and loads that when users hit your site. This will remain even after you clear your cache.