Skip to content

Commit

Permalink
Add manifest caching shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
cransom committed Apr 5, 2024
1 parent 0227e9f commit e78794e
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/zinc/storages/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from urllib.parse import urlparse
import logging

from os.path import exists

import boto3

from . import StorageBackend
Expand Down Expand Up @@ -63,10 +65,16 @@ def _get_keyname(self, subpath):
def get(self, subpath):
keyname = self._get_keyname(subpath)
t = TemporaryFile(mode='w+b')
self._bucket.download_fileobj(keyname, t)
if t.tell() == 0:
return None
t.seek(0)
cache_location = os.environ.get('ZINC_CACHE')
if cache_location and exists(os.path.join(cache_location, keyname)):
log.info(f"GET Cache hit: {subpath} ({keyname})")
t = open(os.path.join(cache_location,keyname), 'rb')
else:
log.info(f"GET Cache miss: {subpath} ({keyname})")
self._bucket.download_fileobj(keyname, t)
if t.tell() == 0:
return None
t.seek(0)
return t

def get_meta(self, subpath):
Expand Down

0 comments on commit e78794e

Please sign in to comment.