Bari.Core.Build.Cache.MemoryBuildCache.Store C# (CSharp) Method

Store() public method

Store build outputs in the cache by reading them from the file system
public Store ( BuildKey builder, IDependencyFingerprint fingerprint, IEnumerable outputs, IFileSystemDirectory targetRoot ) : void
builder BuildKey Builder key (first part of the key)
fingerprint IDependencyFingerprint Dependency fingerprint created when the builder was executed (second part of the key)
outputs IEnumerable Target-relative path of the build outputs to be cached
targetRoot IFileSystemDirectory File system abstraction of the root target directory
return void
        public void Store(BuildKey builder, IDependencyFingerprint fingerprint, IEnumerable<TargetRelativePath> outputs, IFileSystemDirectory targetRoot)
        {
            MemoryCacheItem item = GetOrCreate(builder);

            var map = new ConcurrentDictionary<TargetRelativePath, byte[]>();

            Parallel.ForEach(outputs, outputPath =>
                {
                    if (targetRoot.Exists(outputPath))
                    {
                        using (var stream = targetRoot.ReadBinaryFile(outputPath))
                        {
                            var buf = new byte[stream.Length];
                            stream.Read(buf, 0, buf.Length);

                            map.TryAdd(outputPath, buf);
                        }
                    }
                    else
                    {
                        map.TryAdd(outputPath, null);
                    }
                });

            item.Update(fingerprint, map);
        }