lib/s3repo/cache.rb in s3repo-1.0.0 vs lib/s3repo/cache.rb in s3repo-2.0.0
- old
+ new
@@ -5,35 +5,32 @@
module S3Repo
##
# Cache object, stores S3 objects on disk
class Cache < Base
TMPDIRS = [
- ENV['S3REPO_TMPDIR'],
ENV['TMPDIR'],
Dir.tmpdir,
'/tmp/s3repo'
].freeze
def initialize(params = {})
super
[partialdir, cachedir].each { |x| FileUtils.mkdir_p x }
end
- def serve(key, refresh = true)
- File.open(download(key, refresh), &:read)
- rescue Aws::S3::Errors::NoSuchKey
- nil
- end
-
- private
-
def download(key, refresh = true)
path = expand_path key
get_object(key, path) if refresh || !cached?(path)
path
end
+ private
+
+ def file_cache
+ raise('Tried to call file_cache recursively')
+ end
+
def expand_path(key)
File.absolute_path(key, cachedir)
end
def cached?(path)
@@ -69,9 +66,15 @@
def partialdir
File.join(tmpdir, 'partial')
end
def tmpdir
- @tmpdir ||= File.absolute_path(@options[:tmpdir] || TMPDIRS.compact.first)
+ @tmpdir ||= Dir.mktmpdir 's3repo', tmpdir_root
+ end
+
+ def tmpdir_root
+ @tmpdir_root ||= File.absolute_path(
+ @options[:tmpdir] || TMPDIRS.compact.first
+ )
end
end
end