Caches the given file. Calls process! to trigger any process callbacks.
any kind of file object
if the assigned parameter is a string
# File lib/carrierwave/uploader/cache.rb, line 86 def cache!(new_file) new_file = CarrierWave::SanitizedFile.new(new_file) raise CarrierWave::FormNotMultipart if new_file.is_path? unless new_file.empty? with_callbacks(:cache, new_file) do self.cache_id = CarrierWave.generate_cache_id unless cache_id @filename = new_file.filename self.original_filename = new_file.filename @file = new_file.copy_to(cache_path, permissions) end end end
Returns a String which uniquely identifies the currently cached file for later retrieval
a cache name, in the format YYYYMMDD-HHMM-PID-RND/filename.txt
# File lib/carrierwave/uploader/cache.rb, line 71 def cache_name File.join(cache_id, full_original_filename) if cache_id and original_filename end
Returns true if the uploader has been cached
whether the current file is cached
# File lib/carrierwave/uploader/cache.rb, line 60 def cached? @cache_id end
Retrieves the file with the given #cache_name from the cache.
uniquely identifies a cache file
if the #cache_name is incorrectly formatted.
# File lib/carrierwave/uploader/cache.rb, line 113 def retrieve_from_cache!(cache_name) with_callbacks(:retrieve_from_cache, cache_name) do self.cache_id, self.original_filename = cache_name.to_s.split('/', 2) @filename = original_filename @file = CarrierWave::SanitizedFile.new(cache_path) end end