Rails.cache.clear 和 rake tmp:cache:clear 有什么区别? [英] What is the difference between Rails.cache.clear and rake tmp:cache:clear?

查看:45
本文介绍了Rails.cache.clear 和 rake tmp:cache:clear 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这两个命令是等价的吗?如果不是,有什么区别?

Are the two commands equivalent? If not, what's the difference?

推荐答案

rake 任务只清除存储在 "#{Rails.root}/tmp/cache" 文件系统上的文件.这是该任务的代码.

The rake task only clears out files that are stored on the filesystem in "#{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

Rails.cache.clear 将根据您的应用程序对 config.cache_store 的设置执行不同的操作.http://guides.rubyonrails.org/caching_with_rails.html#cache-stores

Rails.cache.clear will do different things depending on your apps setting for 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" 中删除文件,但实际上可能不会做任何事情因为文件系统上可能没有缓存任何东西.

If you are using config.cache_store = :file_store then Rails.cache.clear will be functionally identical to 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. 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.

这篇关于Rails.cache.clear 和 rake tmp:cache:clear 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆