这两个命令是否等效?如果不是,有什么区别?
66305 次
1 回答
83
rake 任务仅清除存储在文件系统中的文件"#{Rails.root}/tmp/cache"。这是该任务的代码。
namespace :cache do
# desc "Clears all files and directories in tmp/cache"
task :clear do
FileUtils.rm_rf(Dir['tmp/cache/[^.]*'])
end
end
Rails.cache.clear将根据您的应用程序设置做不同的事情config.cache_store。 http://guides.rubyonrails.org/caching_with_rails.html#cache-stores
如果您正在使用config.cache_store = :file_storethenRails.cache.clear将在功能上与rake tmp:cache:clear. 但是,如果您使用其他cache_store的,比如:memory_storeor :mem_cache_store,那么只会Rails.cache.clear清除您的应用缓存。在这种情况下rake tmp:cache:clear,只会尝试从中删除文件,"#{Rails.root}/tmp/cache"但实际上可能不会做任何事情,因为文件系统上可能没有缓存任何内容。
于 2013-09-26T02:29:59.927 回答