Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 961
craig Avatar asked Mar 17 '10 14:03

craig


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?

Memory store Since version 5.0, Rails automatically sets up the :memory_store in the development configuration when generating a new application. When using the memory store, cached data is kept in memory in the Ruby web server's process.

How do I cache a page in Rails?

By default Rails provides fragment caching. 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.


2 Answers

This line in development.rb ensures that caching is not happening.

config.action_controller.perform_caching             = false 

You can clear the Rails cache with

Rails.cache.clear 

That said - I am not convinced this is a caching issue. Are you making changes to the page and not seeing them reflected? You aren't perhaps looking at the live version of that page? I have done that once (blush).

Update:

You can call that command from in the console. Are you sure you are running the application in development?

The only alternative is that the page that you are trying to render isn't the page that is being rendered.

If you watch the server output you should be able to see the render command when the page is rendered similar to this:

Rendered shared_partials/_latest_featured_video (31.9ms) Rendered shared_partials/_s_invite_friends (2.9ms) Rendered layouts/_sidebar (2002.1ms) Rendered layouts/_footer (2.8ms) Rendered layouts/_busy_indicator (0.6ms) 
like image 71
Apie Avatar answered Oct 15 '22 05:10

Apie


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

like image 22
Loren Avatar answered Oct 15 '22 04:10

Loren