/// <summary> /// Bond-serializes a given <typeparamref name="T"/> and stores the result to the content cache. /// The returned content hash can be used to later deserialize the structure with <see cref="TryLoadAndDeserializeContent{T}"/>. /// </summary> public static Task <Possible <ContentHash> > TrySerializeAndStoreContent <T>( this IArtifactContentCache contentCache, T valueToSerialize, BoxRef <long> contentSize = null, StoreArtifactOptions options = default) { return(BondExtensions.TrySerializeAndStoreContent( valueToSerialize, async(valueHash, valueBuffer) => { using (var entryStream = new MemoryStream( valueBuffer.Array, valueBuffer.Offset, valueBuffer.Count, writable: false)) { Possible <Unit, Failure> maybeStored = await contentCache.TryStoreAsync( entryStream, contentHash: valueHash, options: options); return maybeStored.WithGenericFailure(); } }, contentSize)); }
/// <summary> /// Tries to store symlink file to cache. /// </summary> public static async Task <Possible <ContentHash> > TryStoreToCacheAsync( LoggingContext loggingContext, IArtifactContentCache cache, ExpandedAbsolutePath symlinkFile) { var possibleStore = await cache.TryStoreAsync(FileRealizationMode.HardLinkOrCopy, symlinkFile); if (!possibleStore.Succeeded) { Tracing.Logger.Log.FailedStoreSymlinkFileToCache(loggingContext, symlinkFile.ExpandedPath, possibleStore.Failure.DescribeIncludingInnerFailures()); return(possibleStore.Failure); } Logger.Log.SymlinkFileTraceMessage(loggingContext, I($"Stored symlink file '{symlinkFile}' with hash '{possibleStore.Result}'.")); return(possibleStore.Result); }
private static async Task <Possible <Unit> > TryStoreContentAsync( IArtifactContentCache contentCache, ContentHash valueHash, ArraySegment <byte> valueBuffer) { using (var entryStream = new MemoryStream( valueBuffer.Array, valueBuffer.Offset, valueBuffer.Count, writable: false)) { Possible <Unit, Failure> maybeStored = await contentCache.TryStoreAsync( entryStream, contentHash : valueHash); return(maybeStored.WithGenericFailure()); } }
/// <summary> /// Stores the path set content to the backing store /// </summary> protected virtual async Task <Possible <Unit> > TryStorePathSetContentAsync(ContentHash pathSetHash, MemoryStream pathSetBuffer) { Counters.IncrementCounter(PipCachingCounter.StoredPathSetCount); Counters.AddToCounter(PipCachingCounter.StoredPathSetSize, pathSetBuffer.Length); // First check to see if the content is already available in the cache since that's a faster noop path // than storing an already existing PathSet var result = await ArtifactContentCache.TryLoadAvailableContentAsync(new[] { pathSetHash }); if (result.Succeeded && result.Result.AllContentAvailable) { return(Unit.Void); } else { return((await ArtifactContentCache.TryStoreAsync(pathSetBuffer, pathSetHash)).WithGenericFailure()); } }
/// <summary> /// Stores the path set content to the backing store /// </summary> protected virtual async Task <Possible <Unit> > TryStorePathSetContentAsync(ContentHash pathSetHash, MemoryStream pathSetBuffer) { Counters.IncrementCounter(PipCachingCounter.StoredPathSetCount); Counters.AddToCounter(PipCachingCounter.StoredPathSetSize, pathSetBuffer.Length); if (!EngineEnvironmentSettings.SkipExtraneousPins) { // First check to see if the content is already available in the cache since that's a faster noop path // than storing an already existing PathSet var result = await ArtifactContentCache.TryLoadAvailableContentAsync(new[] { pathSetHash }, Context.CancellationToken); if (result.Succeeded && result.Result.AllContentAvailable) { return(Unit.Void); } } return((await ArtifactContentCache.TryStoreAsync(pathSetBuffer, pathSetHash, StoreArtifactOptions.CacheEntryContent)).WithGenericFailure()); }
/// <inheritdoc /> public Task <Possible <Unit, Failure> > TryStoreAsync(FileRealizationMode fileRealizationModes, ExpandedAbsolutePath path, ContentHash contentHash, StoreArtifactOptions options) { return(m_innerCache.TryStoreAsync(fileRealizationModes, path, contentHash, options)); }