{"record":{"id":"e57b546bc2261f1d","repo":"carrierwaveuploader/carrierwave","slug":"need-to-implement-retrieve-from-cache-if-you-wan","errorCode":null,"errorMessage":"Need to implement #retrieve_from_cache! if you want to use #{self.class.name} as a cache storage.","messagePattern":"Need to implement #retrieve_from_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":31,"sourceCode":"        @uploader = uploader\n      end\n\n      def identifier\n        uploader.deduplicated_filename\n      end\n\n      def store!(file)\n      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":13,"sourceCodeEnd":44,"githubUrl":"https://github.com/carrierwaveuploader/carrierwave/blob/b5f0abe10ecf6500309fc83e0e8969cf57ba690e/lib/carrierwave/storage/abstract.rb#L13-L44","documentation":"NotImplementedError raised by the retrieve_from_cache! stub on CarrierWave::Storage::Abstract. It fires when CarrierWave asks the cache storage to fetch a previously cached file — i.e. Uploader::Cache#retrieve_from_cache! (rehydrating the hidden cache field after a failed form submit) or cache_stored_file! before processing — and the active engine never implemented that method.","triggerScenarios":"A custom or store-only storage engine resolving as cache storage (self.class.cache_storage || self.class.storage) while the app round-trips the cache param: uploader.retrieve_from_cache!(params[:image_cache]) in the re-display path, or processing a stored file which calls cache_stored_file!.","commonSituations":"Custom storage authors implementing cache! but forgetting retrieval; re-submitting a form after a validation error once the engine was swapped;CarrierWave versions where fog lacked cache methods.","solutions":["Set config.cache_storage = :file (the default flow: cache on disk, store wherever)","Implement #retrieve_from_cache!(identifier) in your Abstract storage subclass, symmetric with #cache!","Upgrade CarrierWave if you rely on fog storage performing caching"],"exampleFix":"# before\nclass Storage::MyDb < CarrierWave::Storage::Abstract\n  def cache!(file); @db.put(identifier, file.read); end # retrieve_from_cache! missing\nend\n\n# after\nclass Storage::MyDb < CarrierWave::Storage::Abstract\n  def cache!(file); @db.put(identifier, file.read); end\n  def retrieve_from_cache!(identifier)\n    CacheFile.new(@db.get(identifier), identifier)\n  end\nend","handlingStrategy":"validation","validationCode":"cache_engine = (MyUploader.cache_storage || MyUploader.storage)\nraise \"cache storage must implement #retrieve_from_cache!\" unless cache_engine.instance_methods.include?(:retrieve_from_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":["Implement #retrieve_from_cache! symmetric with #cache! in custom storages","Exercise the form round-trip (validation failure -> re-render -> retrieve_from_cache!) in specs for every storage engine you ship","Keep cache_storage = :file unless your engine deliberately implements the whole cache interface"],"tags":["carrierwave","storage","custom-storage","cache","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"}