gpt4 book ai didi

ruby-on-rails - Rails.cache.clear 和 rake tmp :cache:clear? 之间有什么区别

转载 作者:行者123 更新时间:2023-12-03 06:00:05 33 4
gpt4 key购买 nike

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

最佳答案

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_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" 中删除文件,但实际上可能不会执行任何操作因为文件系统上可能没有缓存任何内容。

关于ruby-on-rails - Rails.cache.clear 和 rake tmp :cache:clear? 之间有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19017983/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com