簡體   English   中英

Rails.cache.clear和rake tmp:cache:clear有什么區別?

[英]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

https://github.com/rails/rails/blob/ef5d85709d346e55827e88f53430a2cbe1e5fb9e/railties/lib/rails/tasks/tmp.rake#L25-L30

Rails.cache.clear將根據您的config.cache_store應用程序設置執行不同的操作。 http://guides.rubyonrails.org/caching_with_rails.html#cache-stores

如果您使用config.cache_store = :file_storeRails.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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM