[英]What is the difference between Rails.cache.clear and rake tmp:cache:clear?
這兩個命令是否等效? 如果沒有,有什么區別?
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_store
則Rails.cache.clear
在功能上將與rake tmp:cache:clear
。 但是,如果您使用其他其他cache_store
,例如:memory_store
或:mem_cache_store
,則只有Rails.cache.clear
會清除您的應用程序緩存。 在那種情況下, rake tmp:cache:clear
只會嘗試從"#{Rails.root}/tmp/cache"
刪除文件,但實際上可能不會做任何事情,因為文件系統上可能沒有緩存。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.