in legacy/adobe_tools/adobe_api.py [0:0]
def __read_cache(self):
"""Read the values from the cache file."""
cache_data = {}
try:
# Invalidate the cache automatically after 2 weeks, plus splay
file_age = os.path.getmtime(self.cache_path)
# Splay is a number of hours added to the cache invalidation time
# It can be negative, so that clients don't all hit at once.
splay_seconds = 60 * 60 * int(self.splay)
two_weeks = (60 * 60 * 24 * 14)
if time.time() - file_age < (two_weeks + splay_seconds):
with open(self.cache_path, 'rb') as f:
cache_data = json.load(f)
except (OSError, IOError, ValueError):
# Cache doesn't exist, or is invalid
self.user = {}
return
productlist = cache_data.get('productlist', [])
if productlist:
self.productlist = productlist
userlist = cache_data.get('userlist', [])
if userlist:
self.userlist = userlist
user_data = cache_data.get('user_data', {})
if user_data and user_data.get(self.key) == self.username:
self.user = user_data
else:
# Look through the userlist to see if we find the username.
# If not, the result is an empty dict anyway.
self.user = self.data()