简体   繁体   English

Rails.cache.clear和rake tmp:cache:clear有什么区别?

[英]What is the difference between Rails.cache.clear and rake tmp:cache:clear?

Are the two commands equivalent? 这两个命令是否等效? If not, what's the difference? 如果没有,有什么区别?

The rake task only clears out files that are stored on the filesystem in "#{Rails.root}/tmp/cache" . rake任务仅清除"#{Rails.root}/tmp/cache"中存储在文件系统中的文件。 Here's the code for that task. 这是该任务的代码。

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 https://github.com/rails/rails/blob/ef5d85709d346e55827e88f53430a2cbe1e5fb9e/railties/lib/rails/tasks/tmp.rake#L25-L30

Rails.cache.clear will do different things depending on your apps setting for config.cache_store . Rails.cache.clear将根据您的config.cache_store应用程序设置执行不同的操作。 http://guides.rubyonrails.org/caching_with_rails.html#cache-stores http://guides.rubyonrails.org/caching_with_rails.html#cache-stores

If you are using config.cache_store = :file_store then Rails.cache.clear will be functionally identical to rake tmp:cache:clear . 如果您使用config.cache_store = :file_storeRails.cache.clear在功能上将与rake tmp:cache:clear However, if you're using some other cache_store , like :memory_store or :mem_cache_store , then only Rails.cache.clear will clear your app cache. 但是,如果您使用其他其他cache_store ,例如:memory_store:mem_cache_store ,则只有Rails.cache.clear会清除您的应用程序缓存。 In that case rake tmp:cache:clear will just try to remove files from "#{Rails.root}/tmp/cache" but probably won't actually do anything since nothing is probably being cached on the filesystem. 在那种情况下, rake tmp:cache:clear只会尝试从"#{Rails.root}/tmp/cache"删除文件,但实际上可能不会做任何事情,因为文件系统上可能没有缓存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM