Created
November 15, 2017 00:18
-
-
Save aaron-prindle/76b705549a0521051fc9da1e7b3587c3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def GetCacheKey(self, descriptor_files): | |
| descriptor = None | |
| for f in descriptor_files: | |
| if self.ctx.Contains(f): | |
| descriptor = f | |
| descriptor_contents = self.ctx.GetFile(descriptor) | |
| break | |
| if not descriptor: | |
| logging.info('No package descriptor found. No packages installed.') | |
| return None | |
| return hashlib.sha256(descriptor_contents).hexdigest() | |
| def GetCachedImageIfExists(self, checksum): | |
| # def GetCachedImageIfExists(self, base_image, cache, use_cache=True): | |
| if not checksum: | |
| # TODO(aaron-prindle) verify this makes sense to use None | |
| # as sentinel for no descriptor and to handle this here | |
| return base_image | |
| hit = cache.Get(base_image, _PYTHON_NAMESPACE, checksum) | |
| if hit: | |
| logging.info('Found cached dependency layer for %s' % checksum) | |
| last_created = _timestamp_to_time(_creation_time(hit)) | |
| now = datetime.datetime.now() | |
| if last_created > now - datetime.timedelta( | |
| seconds=_DEFAULT_TTL_WEEKS): | |
| return hit | |
| else: | |
| logging.info('TTL expired for cached image, rebuilding %s' | |
| % checksum) | |
| else: | |
| logging.info('No cached dependency layer for %s' % checksum) | |
| return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment