Exemple #1
0
        /// <summary>
        /// Store build outputs in the cache by reading them from the file system
        /// </summary>
        /// <param name="builder">Builder key (first part of the key)</param>
        /// <param name="fingerprint">Dependency fingerprint created when the builder was executed (second part of the key)</param>
        /// <param name="outputs">Target-relative path of the build outputs to be cached</param>
        /// <param name="targetRoot">File system abstraction of the root target directory</param>
        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);
        }
Exemple #2
0
        private MemoryCacheItem GetOrCreate(BuildKey builder)
        {
            Contract.Ensures(Contract.Result <MemoryCacheItem>() != null);

            lock (cache)
            {
                MemoryCacheItem item;
                if (!cache.TryGetValue(builder, out item))
                {
                    item = new MemoryCacheItem();
                    cache.Add(builder, item);
                }

                Contract.Assume(item != null);
                return(item);
            }
        }
Exemple #3
0
        private MemoryCacheItem GetOrCreate(BuildKey builder)
        {
            Contract.Ensures(Contract.Result<MemoryCacheItem>() != null);

            lock (cache)
            {
                MemoryCacheItem item;
                if (!cache.TryGetValue(builder, out item))
                {
                    item = new MemoryCacheItem();
                    cache.Add(builder, item);
                }

                Contract.Assume(item != null);
                return item;
            }
        }