Module: CarrierWave::Uploader::Cache::ClassMethods
- Defined in:
- lib/carrierwave/uploader/cache.rb
Instance Method Summary collapse
-
#clean_cached_files! ⇒ Object
Removes cached files which are older than one day.
Instance Method Details
#clean_cached_files! ⇒ Object
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 keep cache files in one place only.
44 45 46 47 48 49 50 51 52 |
# File 'lib/carrierwave/uploader/cache.rb', line 44 def clean_cached_files! Dir.glob(File.(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 |