Are the two commands equivalent? If not, what's the difference?
Rake is a popular task runner for Ruby and Rails applications. For example, Rails provides the predefined Rake tasks for creating databases, running migrations, and performing tests. You can also create custom tasks to automate specific actions - run code analysis tools, backup databases, and so on.
Page caches are always stored on disk. Rails 2.1 and above provide ActiveSupport::Cache::Store which can be used to cache strings. Some cache store implementations, like MemoryStore, are able to cache arbitrary Ruby objects, but don't count on every cache store to be able to do that.
To use Redis as a Rails cache store, use a dedicated cache instance that's set up as an LRU (Last Recently Used) cache instead of pointing the store at your existing Redis server, to make sure entries are dropped from the store when it reaches its maximum size.
Custom rake tasks have a . rake extension and are placed in Rails. root/lib/tasks . You can create these custom rake tasks with the bin/rails generate task command.
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
will do different things depending on your apps setting for config.cache_store
. 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
. 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With