Search code examples
ruby-on-railsrubyrestartcentos7

Remove Rails cache without restarting the server


I have an app running on Ruby 1.9.3p551 and Rails 3.2.12

Every time I make changes to the code I need to restart Ruby to get them. I have configured the environment as development and in the config/environments/development.rb file I setted:

 config.cache_classes = false
 config.action_controller.perform_caching = false

But I still need to restart the server.

My OS is Centos 7.


Solution

  • The reason you have to restart your server when you make changes is not because of application caching. In fact, according to the helpful Rails caching guide, caching doesn't even take place in development/test environments by default. The real reason you have to restart your server is because one of the jobs of starting a server is to load the Rails application code. And whatever changes you make to the Rails application files doesn't change the currently loaded code. Thus, you need to reload the code by restarting the server.

    However, there are alternatives: A gem called spring, is specifically designed to address the issue of development application reloading (it comes as a standard gem with Rails 4):

    • Totally automatic; no need to explicitly start and stop the background process
    • Reloads your application code on each run
    • Restarts your application when configs / initializers / gem dependencies are changed

    This way, your application is reloaded each time you make a change to your application

    Just put this in your Gemfile

    gem "spring", group: :development
    

    and then run,

    $ bundle install
    $ bundle exec spring binstub --all
    

    Also, make sure that caching is off when it comes to your browser(s).