【发布时间】:2013-09-26 01:43:55
【问题描述】:
这两个命令是否等效?如果不是,有什么区别?
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.2 rake
这两个命令是否等效?如果不是,有什么区别?
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.2 rake
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" 中删除文件,但实际上可能不会做任何事情,因为文件系统上可能没有缓存任何内容。
【讨论】: