Rails clear cache task
rails tmp:clear task clears the file cache.
$ rails tmp:clear # Clear cache, socket and screenshot files from tmp/ (narrow w/ tmp:cache:clear, tmp:sockets:clear, tmp:screenshots:clear)
The implementation
namespace :tmp do
desc "Clear cache, socket and screenshot files from tmp/ (narrow w/ tmp:cache:clear, tmp:sockets:clear, tmp:screenshots:clear)"
task clear: ["tmp:cache:clear", "tmp:sockets:clear", "tmp:screenshots:clear", "tmp:storage:clear"]
...
end
The each task just deletes directories inside tmp.
namespace :cache do
# desc "Clears all files and directories in tmp/cache"
task :clear do
rm_rf Dir["tmp/cache/[^.]*"], verbose: false
end
end
The difference between Rails.cache.clear and rails tmp:cache:clear
If you are using
config.cache_store = :file_storethenRails.cache.clearwill be functionally identical torake tmp:cache:clear. However, if you’re using some other cache_store, like:memory_storeor:mem_cache_store, then onlyRails.cache.clearwill clear your app cache.
ref. What is the difference between Rails.cache.clear and rake tmp:cache:clear? - Stack Overflow