private static async Task <Possible <Stream, Failure> > TryGetStreamFromContentHash( IArtifactContentCache contentCache, ContentHash contentHash, CancellationToken cancellationToken, BoxRef <long> contentSize = null) { if (!EngineEnvironmentSettings.SkipExtraneousPins) { Possible <ContentAvailabilityBatchResult, Failure> maybeAvailable = await contentCache.TryLoadAvailableContentAsync(new[] { contentHash }, cancellationToken); if (!maybeAvailable.Succeeded) { return(maybeAvailable.Failure); } bool contentIsAvailable = maybeAvailable.Result.AllContentAvailable; if (!contentIsAvailable) { return(default(Stream)); } } var maybeStream = await contentCache.TryOpenContentStreamAsync(contentHash); if (!maybeStream.Succeeded) { if (maybeStream.Failure is NoCasEntryFailure) { return(default(Stream)); } return(maybeStream.Failure); } Stream stream = maybeStream.Result; if (contentSize != null) { contentSize.Value = stream.Length; } return(stream); }
/// <summary> /// Combined load+open. This assumes that the named content is probably available (e.g. named in a cache entry) /// and so soft misses are promoted to failures. /// </summary> protected virtual async Task <Possible <Stream> > TryLoadContentAndOpenStreamAsync(ContentHash contentHash) { Possible <ContentAvailabilityBatchResult> maybeAvailable = await ArtifactContentCache.TryLoadAvailableContentAsync(new[] { contentHash }); if (!maybeAvailable.Succeeded) { return(maybeAvailable.Failure); } bool contentIsAvailable = maybeAvailable.Result.AllContentAvailable; if (!contentIsAvailable) { return(new Failure <string>("Required content is not available in the cache")); } return(await ArtifactContentCache.TryOpenContentStreamAsync(contentHash)); }
/// <summary> /// Combined load+open. This assumes that the named content is probably available (e.g. named in a cache entry) /// and so soft misses are promoted to failures. /// </summary> protected virtual async Task <Possible <StreamWithLength> > TryLoadContentAndOpenStreamAsync(ContentHash contentHash) { if (!EngineEnvironmentSettings.SkipExtraneousPins) { Possible <ContentAvailabilityBatchResult> maybeAvailable = await ArtifactContentCache.TryLoadAvailableContentAsync(new[] { contentHash }, Context.CancellationToken); if (!maybeAvailable.Succeeded) { return(maybeAvailable.Failure); } bool contentIsAvailable = maybeAvailable.Result.AllContentAvailable; if (!contentIsAvailable) { return(new Failure <string>("Required content is not available in the cache")); } } return(await ArtifactContentCache.TryOpenContentStreamAsync(contentHash)); }
private static async Task <Possible <Stream, Failure> > TryGetStreamFromContentHash( IArtifactContentCache contentCache, ContentHash contentHash, BoxRef <long> contentSize = null) { Possible <ContentAvailabilityBatchResult, Failure> maybeAvailable = await contentCache.TryLoadAvailableContentAsync(new[] { contentHash }); if (!maybeAvailable.Succeeded) { return(maybeAvailable.Failure); } bool contentIsAvailable = maybeAvailable.Result.AllContentAvailable; if (!contentIsAvailable) { return(default(Stream)); } var maybeStream = await contentCache.TryOpenContentStreamAsync(contentHash); if (!maybeStream.Succeeded) { return(maybeStream.Failure); } Stream stream = maybeStream.Result; if (contentSize != null) { contentSize.Value = stream.Length; } return(stream); }
/// <inheritdoc /> public Task <Possible <StreamWithLength, Failure> > TryOpenContentStreamAsync(ContentHash contentHash) { return(m_innerCache.TryOpenContentStreamAsync(contentHash)); }