Пример #1
0
 /// <inheritdoc />
 public Task <Possible <CacheEntryPublishResult, Failure> > TryPublishCacheEntryAsync(
     WeakContentFingerprint weakFingerprint,
     ContentHash pathSetHash,
     StrongContentFingerprint strongFingerprint,
     CacheEntry entry,
     CacheEntryPublishMode mode       = CacheEntryPublishMode.CreateNew,
     PublishCacheEntryOptions options = default)
 {
     return(Task.FromResult(new Possible <CacheEntryPublishResult, Failure>(CacheEntryPublishResult.CreatePublishedResult())));
 }
Пример #2
0
        /// <inheritdoc />
        public Task <Possible <CacheEntryPublishResult, Failure> > TryPublishCacheEntryAsync(
            WeakContentFingerprint weakFingerprint,
            ContentHash pathSetHash,
            StrongContentFingerprint strongFingerprint,
            CacheEntry entry,
            CacheEntryPublishMode mode       = CacheEntryPublishMode.CreateNew,
            PublishCacheEntryOptions options = default)
        {
            var newNode     = new Node(pathSetHash, strongFingerprint, entry);
            var updatedNode = m_entries.AddOrUpdate(
                weakFingerprint,
                newNode,
                (key, node) => node,
                (key, node, existingNode) =>
            {
                Node currentNode = existingNode;
                Node priorNode   = null;
                while (currentNode != null)
                {
                    if (node.PathSetHash == currentNode.PathSetHash && node.StrongFingerprint == currentNode.StrongFingerprint)
                    {
                        if (mode == CacheEntryPublishMode.CreateNewOrReplaceExisting)
                        {
                            if (priorNode != null)
                            {
                                priorNode.Next = node;
                            }

                            node.Next = node;
                        }

                        return(existingNode);
                    }

                    priorNode   = currentNode;
                    currentNode = currentNode.Next;
                }

                node.Next = existingNode;
                return(node);
            }).Item.Value;

            if (mode == CacheEntryPublishMode.CreateNew)
            {
                if (updatedNode != newNode)
                {
                    return(Task.FromResult(new Possible <CacheEntryPublishResult, Failure>(CacheEntryPublishResult.CreateConflictResult(updatedNode.CacheEntry))));
                }
            }

            return(Task.FromResult(new Possible <CacheEntryPublishResult, Failure>(CacheEntryPublishResult.CreatePublishedResult())));
        }