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_store
thenRails.cache.clear
will be functionally identical torake tmp:cache:clear
. However, if you’re using some other cache_store, like:memory_store
or:mem_cache_store
, then onlyRails.cache.clear
will clear your app cache.
ref. What is the difference between Rails.cache.clear and rake tmp:cache:clear? - Stack Overflow