📎 Webclip
Caching in development environment in Rails 5
Rails 5 adds a command for turning development caching on and off without editing config/environments/development.rb by hand. The command creates or removes tmp/caching-dev.txt, and the app uses that file to decide whether caching is enabled in development.
Reading notes#
- In Rails 4, enabling caching in development required changing
configaction_controllerperform_cachinginconfig/environments/development.rband restarting the server. - Rails 5 introduces
rails dev:cacheto help test caching behavior in development mode. - Running
rails dev:cachecreatestmp/caching-dev.txtand prints that development mode is now being cached. - In a new Rails 5 app,
development.rbchecks whethertmp/caching-dev.txtexists and then uses:mem_cache_storewhen it does. - The dev cache code toggles the file in
tmp/caching-dev.txtand touchestmp/restart.txt. - The advantage is that caching can be turned on or off without restarting the server manually.
- The feature is not supported by unicorn, thin, and webrick.
- Running
rails dev:cacheagain disables development caching if it was previously enabled.
