/// <inheritdoc /> public async Task <ObjectResult <ContentHashListWithCacheMetadata> > AddContentHashListAsync( Context context, string cacheNamespace, StrongFingerprint strongFingerprint, ContentHashListWithCacheMetadata valueToAdd, bool forceUpdate) { try { ContentHashListResponse addResult = await ArtifactHttpClientErrorDetectionStrategy.ExecuteWithTimeoutAsync( context, "AddContentHashList", innerCts => _buildCacheHttpClient.AddContentHashListAsync( cacheNamespace, strongFingerprint, valueToAdd, forceUpdate), CancellationToken.None).ConfigureAwait(false); // The return value is null if the server fails adding content hash list to the backing store. // See BuildCacheService.AddContentHashListAsync for more details about the implementation invariants/guarantees. if (addResult != null) { DownloadUriCache.Instance.BulkAddDownloadUris(addResult.BlobDownloadUris); } // add succeeded but returned an empty contenthashlistwith cache metadata. correct this. if (addResult?.ContentHashListWithCacheMetadata == null) { return (new ObjectResult <ContentHashListWithCacheMetadata>( new ContentHashListWithCacheMetadata( new ContentHashListWithDeterminism(null, valueToAdd.ContentHashListWithDeterminism.Determinism), valueToAdd.GetRawExpirationTimeUtc(), valueToAdd.ContentGuarantee, valueToAdd.HashOfExistingContentHashList))); } else if (addResult.ContentHashListWithCacheMetadata.ContentHashListWithDeterminism.ContentHashList != null && addResult.ContentHashListWithCacheMetadata.HashOfExistingContentHashList == null) { return(new ObjectResult <ContentHashListWithCacheMetadata>( new ContentHashListWithCacheMetadata( addResult.ContentHashListWithCacheMetadata.ContentHashListWithDeterminism, addResult.ContentHashListWithCacheMetadata.GetRawExpirationTimeUtc(), addResult.ContentHashListWithCacheMetadata.ContentGuarantee, addResult.ContentHashListWithCacheMetadata.ContentHashListWithDeterminism.ContentHashList.GetHashOfHashes()))); } else { return(new ObjectResult <ContentHashListWithCacheMetadata>(addResult.ContentHashListWithCacheMetadata)); } } catch (Exception ex) { return(new ObjectResult <ContentHashListWithCacheMetadata>(ex)); } }
/// <inheritdoc /> public async Task <ObjectResult <ContentHashListWithCacheMetadata> > AddContentHashListAsync( Context context, string cacheNamespace, StrongFingerprint strongFingerprint, ContentHashListWithCacheMetadata valueToAdd) { try { ContentHashListResponse addResult = await ArtifactHttpClientErrorDetectionStrategy.ExecuteWithTimeoutAsync( context, "AddContentHashList", innerCts => _buildCacheHttpClient.AddContentHashListAsync( cacheNamespace, strongFingerprint, valueToAdd), CancellationToken.None).ConfigureAwait(false); DownloadUriCache.Instance.BulkAddDownloadUris(addResult.BlobDownloadUris); // add succeeded but returned an empty contenthashlistwith cache metadata. correct this. if (addResult.ContentHashListWithCacheMetadata == null) { return (new ObjectResult <ContentHashListWithCacheMetadata>( new ContentHashListWithCacheMetadata( new ContentHashListWithDeterminism(null, valueToAdd.ContentHashListWithDeterminism.Determinism), valueToAdd.GetEffectiveExpirationTimeUtc(), valueToAdd.ContentGuarantee, valueToAdd.HashOfExistingContentHashList))); } else if (addResult.ContentHashListWithCacheMetadata.ContentHashListWithDeterminism.ContentHashList != null && addResult.ContentHashListWithCacheMetadata.HashOfExistingContentHashList == null) { return(new ObjectResult <ContentHashListWithCacheMetadata>( new ContentHashListWithCacheMetadata( addResult.ContentHashListWithCacheMetadata.ContentHashListWithDeterminism, addResult.ContentHashListWithCacheMetadata.GetEffectiveExpirationTimeUtc(), addResult.ContentHashListWithCacheMetadata.ContentGuarantee, addResult.ContentHashListWithCacheMetadata.ContentHashListWithDeterminism.ContentHashList.GetHashOfHashes()))); } else { return(new ObjectResult <ContentHashListWithCacheMetadata>(addResult.ContentHashListWithCacheMetadata)); } } catch (Exception ex) { return(new ObjectResult <ContentHashListWithCacheMetadata>(ex)); } }
/// <inheritdoc /> public async Task <Result <ContentHashListWithCacheMetadata> > GetContentHashListAsync( Context context, string cacheNamespace, StrongFingerprint strongFingerprint) { try { ContentHashListResponse response = await ArtifactHttpClientErrorDetectionStrategy.ExecuteWithTimeoutAsync( context, "GetContentHashList", innerCts => _buildCacheHttpClient.GetContentHashListAsync(cacheNamespace, strongFingerprint), CancellationToken.None).ConfigureAwait(false); DownloadUriCache.Instance.BulkAddDownloadUris(response.BlobDownloadUris); // our response should never be null. if (response.ContentHashListWithCacheMetadata != null) { return(new Result <ContentHashListWithCacheMetadata>(response.ContentHashListWithCacheMetadata)); } return(new Result <ContentHashListWithCacheMetadata>(EmptyContentHashList)); } catch (CacheServiceException ex) when(ex.ReasonCode == CacheErrorReasonCode.ContentHashListNotFound) { return(new Result <ContentHashListWithCacheMetadata>(EmptyContentHashList)); } catch (ContentBagNotFoundException) { return(new Result <ContentHashListWithCacheMetadata>(EmptyContentHashList)); } catch (VssServiceResponseException serviceEx) when(serviceEx.HttpStatusCode == HttpStatusCode.NotFound) { // Currently expect the Item-based service to return VssServiceResponseException on misses, // but the other catches have been left for safety/compat. return(new Result <ContentHashListWithCacheMetadata>(EmptyContentHashList)); } catch (Exception ex) { return(new Result <ContentHashListWithCacheMetadata>(ex)); } }