Class: S3Repo::Cache

Inherits:
Base
  • Object
show all
Defined in:
lib/s3repo/cache.rb

Overview

Cache object, stores S3 objects on disk

Constant Summary collapse

TMPDIRS =
[ENV['S3REPO_TMPDIR'], ENV['TMPDIR'], '/tmp/s3repo']

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Cache

Returns a new instance of Cache.



10
11
12
13
# File 'lib/s3repo/cache.rb', line 10

def initialize(params = {})
  super
  [partialdir, cachedir].each { |x| FileUtils.mkdir_p x }
end

Instance Method Details

#serve(path, recheck = true) ⇒ Object



15
16
17
18
19
20
# File 'lib/s3repo/cache.rb', line 15

def serve(path, recheck = true)
  epath = expand_path(path)
  prune(path, epath) if recheck
  download(path, epath) unless File.exist?(epath)
  File.open(epath) { |fh| fh.read }
end