class Hasta::ResolveCachedS3File
Retrieves a file from the local cache instead of S3, or retrieves it from S3 and caches it locally
Attributes
child_resolver[R]
file_cache[R]
Public Class Methods
new(file_cache, child_resolver)
click to toggle source
# File lib/hasta/resolve_cached_s3_file.rb, line 10 def initialize(file_cache, child_resolver) @file_cache = file_cache @child_resolver = child_resolver end
Public Instance Methods
resolve(fog_file)
click to toggle source
# File lib/hasta/resolve_cached_s3_file.rb, line 15 def resolve(fog_file) resolved = child_resolver.resolve(fog_file) if cached_file = file_cache.get(resolved.fingerprint) Hasta.logger.debug "Retrieved file: #{resolved.s3_uri} from local cache" CachedS3File.new(cached_file, resolved.s3_uri) else file_cache.put(resolved.fingerprint, resolved.body) Hasta.logger.debug "Cached file: #{resolved.s3_uri} locally" resolved end end