module CarrierWave::Uploader::Cache::ClassMethods

Public Instance Methods

clean_cached_files!() click to toggle source

Removes cached files which are older than one day. You could call this method from a rake task to clean out old cached files.

You can call this method directly on the module like this:

CarrierWave.clean_cached_files!

Note

This only works as long as you haven’t done anything funky with your cache_dir. It’s recommended that you keen cache files in one place only.

# File lib/carrierwave/uploader/cache.rb, line 42
def clean_cached_files!
  Dir.glob(File.expand_path(File.join(cache_dir, '*'), CarrierWave.root)).each do |dir|
    time = dir.scan(/(\d{4})(\d{2})(\d{2})-(\d{2})(\d{2})/).first.map { |t| t.to_i }
    time = Time.utc(*time)
    if time < (Time.now - (60*60*24))
      FileUtils.rm_rf(dir)
    end
  end
end