summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2020-09-17 11:04:15 +0200
committerJürg Billeter <j@bitron.ch>2020-12-14 07:35:03 +0100
commit1bcf62cb817ec321a38131dc2a0506609e537f8e (patch)
treea4672ce6aa8e86a606c49e7d9e9b676873641a85
parenta01826eb65729e3d8cc3c0a528c18798f667cb8f (diff)
downloadbuildstream-1bcf62cb817ec321a38131dc2a0506609e537f8e.tar.gz
_elementsources.py: Make cache query explicit
Cache query can be fairly expensive as it checks the presence of all blobs. Make this more explicit with a `query_cache()` method, instead of implicitly querying the cache on the first call to `cached()`.
-rw-r--r--src/buildstream/_elementsources.py21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/buildstream/_elementsources.py b/src/buildstream/_elementsources.py
index a15d20ecb..a3e510543 100644
--- a/src/buildstream/_elementsources.py
+++ b/src/buildstream/_elementsources.py
@@ -293,7 +293,7 @@ class ElementSources:
length = min(len(key), context.log_key_length)
return key[:length]
- # cached():
+ # query_cache():
#
# Check if the element sources are cached in CAS, generating the source
# cache keys if needed.
@@ -301,10 +301,7 @@ class ElementSources:
# Returns:
# (bool): True if the element sources are cached
#
- def cached(self):
- if self._cached is not None:
- return self._cached
-
+ def query_cache(self):
cas = self._context.get_cascache()
elementsourcescache = self._elementsourcescache
@@ -321,6 +318,18 @@ class ElementSources:
self._cached = True
return True
+ # cached()
+ #
+ # Return whether the element sources are cached in CAS. This must be
+ # called only when all sources are resolved.
+ #
+ # Returns:
+ # (bool): True if the element sources are cached
+ #
+ def cached(self):
+ assert self._cached is not None
+ return self._cached
+
# is_resolved():
#
# Get whether all sources of the element are resolved
@@ -368,6 +377,8 @@ class ElementSources:
unique_key = self.get_unique_key()
self._cache_key = _cachekey.generate_key(unique_key)
+ self.query_cache()
+
# preflight():
#
# A internal wrapper for calling the abstract preflight() method on