Class: Hasta::ResolveCachedS3File

Inherits:
Object
  • Object
show all
Defined in:
lib/hasta/resolve_cached_s3_file.rb

Overview

Retrieves a file from the local cache instead of S3, or retrieves it from S3 and caches it locally

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_cache, child_resolver) ⇒ ResolveCachedS3File

Returns a new instance of ResolveCachedS3File.



10
11
12
13
# 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

Instance Attribute Details

#child_resolverObject (readonly)

Returns the value of attribute child_resolver.



27
28
29
# File 'lib/hasta/resolve_cached_s3_file.rb', line 27

def child_resolver
  @child_resolver
end

#file_cacheObject (readonly)

Returns the value of attribute file_cache.



27
28
29
# File 'lib/hasta/resolve_cached_s3_file.rb', line 27

def file_cache
  @file_cache
end

Instance Method Details

#resolve(fog_file) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# 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