public static async Task <Possible <Unit> > TryPublishTemporalCacheEntryAsync(
            this ITwoPhaseFingerprintStore store,
            LoggingContext loggingContext,
            ContentFingerprint fingerprint,
            CacheEntry entry,
            DateTime?time = null)
        {
            // Attempt to store the cache entry into all the time buckets
            var node  = new TimeTreeNode(time);
            var tasks = new List <Task <Possible <CacheEntryPublishResult, Failure> > >();

            while (node != null)
            {
                tasks.Add(store.TryPublishNodeTemporalCacheEntryAsync(
                              loggingContext,
                              node,
                              fingerprint,
                              entry));

                node = node.Parent;
            }

            await Task.WhenAll(tasks);

            foreach (var task in tasks)
            {
                if (!task.Result.Succeeded)
                {
                    return(task.Result.Failure);
                }
            }

            return(Unit.Void);
        }
Esempio n. 2
0
        public static async Task <Possible <Unit> > TryPublishTemporalCacheEntryAsync(
            this ITwoPhaseFingerprintStore store,
            LoggingContext loggingContext,
            ContentFingerprint fingerprint,
            CacheEntry entry,
            DateTime?time = null)
        {
            // Attempt to store the cache entry into all the time buckets
            var node  = new TimeTreeNode(time);
            var tasks = new List <Task <Possible <CacheEntryPublishResult, Failure> > >();

            while (node != null)
            {
                tasks.Add(store.TryPublishNodeTemporalCacheEntryAsync(
                              loggingContext,
                              node,
                              fingerprint,
                              entry));

                // Don't store full cache entry for parent nodes since time tree addition
                // will trigger pins (and consequently downloads) of content for conflicting entries
                entry = new CacheEntry(entry.MetadataHash, entry.OriginatingCache, ArrayView <ContentHash> .Empty);

                node = node.Parent;
            }

            await Task.WhenAll(tasks);

            foreach (var task in tasks)
            {
                if (!task.Result.Succeeded)
                {
                    return(task.Result.Failure);
                }
            }

            return(Unit.Void);
        }