{"record":{"id":"0d1cdb1b5f7026b3","repo":"carrierwaveuploader/carrierwave","slug":"need-to-implement-clean-cache-if-you-want-to-use","errorCode":null,"errorMessage":"Need to implement #clean_cache! if you want to use #{self.class.name} as a cache storage.","messagePattern":"Need to implement #clean_cache! if you want to use #(.+?) as a cache storage\\.","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"lib/carrierwave/storage/abstract.rb","lineNumber":39,"sourceCode":"      end\n\n      def retrieve!(identifier)\n      end\n\n      def cache!(new_file)\n        raise NotImplementedError, \"Need to implement #cache! if you want to use #{self.class.name} as a cache storage.\"\n      end\n\n      def retrieve_from_cache!(identifier)\n        raise NotImplementedError, \"Need to implement #retrieve_from_cache! if you want to use #{self.class.name} as a cache storage.\"\n      end\n\n      def delete_dir!(path)\n        raise NotImplementedError, \"Need to implement #delete_dir! if you want to use #{self.class.name} as a cache storage.\"\n      end\n\n      def clean_cache!(seconds)\n        raise NotImplementedError, \"Need to implement #clean_cache! if you want to use #{self.class.name} as a cache storage.\"\n      end\n    end # Abstract\n  end # Storage\nend # CarrierWave\n","sourceCodeStart":21,"sourceCodeEnd":44,"githubUrl":"https://github.com/carrierwaveuploader/carrierwave/blob/b5f0abe10ecf6500309fc83e0e8969cf57ba690e/lib/carrierwave/storage/abstract.rb#L21-L44","documentation":"NotImplementedError raised by the clean_cache! stub on CarrierWave::Storage::Abstract. It fires when cache expiry is requested — usually the CarrierWave.clean_cached_files! rake task / Uploader::Base.clean_cached_files! — and the configured cache storage engine never implemented timed cleanup of the cache directory.","triggerScenarios":"Running CarrierWave.clean_cached_files! (scheduled rake task or cron) while the resolved cache storage (self.class.cache_storage || self.class.storage) is an engine without clean_cache! — e.g. a custom store-only storage, or cache_storage pointing at a non-file engine on versions lacking implementations.","commonSituations":"Adding the standard daily cache-cleaning cron after switching storages; custom storage engines built only for store/retrieve; CI running the maintenance task against a stub storage.","solutions":["Set config.cache_storage = :file and let the built-in File storage clean its cache dir","Implement #clean_cache!(seconds) in your storage subclass (delete entries older than the cutoff)","Skip/scope clean_cached_files! to uploaders whose cache storage actually supports it"],"exampleFix":"# before\n# lib/tasks/carrierwave.rake\ntask :clean_cache => :environment do\n  CarrierWave.clean_cached_files! # NotImplementedError with store-only storage\nend\n\n# after\ntask :clean_cache => :environment do\n  CarrierWave.configure { |c| c.cache_storage = :file }\n  CarrierWave.clean_cached_files!\nend","handlingStrategy":"validation","validationCode":"MyUploader.clean_cached_files! if (MyUploader.cache_storage || MyUploader.storage).instance_methods.include?(:clean_cache!)","typeGuard":"def cache_capable_storage?(klass)\n  %i[cache! retrieve_from_cache! delete_dir! clean_cache!].all? { |m| klass.instance_methods.include?(m) }\nend","tryCatchPattern":null,"preventionTips":["Run clean_cached_files! only against uploaders whose cache storage implements #clean_cache!","Schedule cache cleaning via the standard rake task with cache_storage = :file","Add a spec that invokes clean_cache! on every shipped storage engine"],"tags":["carrierwave","storage","custom-storage","cache","cleanup","not-implemented"],"backgroundTag":"abstract-method-not-implemented","analyzedSha":"b5f0abe10ecf6500309fc83e0e8969cf57ba690e","analyzedAt":"2026-08-21T18:07:27.715Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}