Пример #1
0
        private async Task <ExistenceResponse> CheckFileExistsAsync(ExistenceRequest request, CancellationToken token)
        {
            LogRequestHandling();

            Debug.Assert(_contentStoreByCacheName != null);

            DateTime    startTime    = DateTime.UtcNow;
            Context     cacheContext = new Context(new Guid(request.TraceId), _logger);
            HashType    type         = (HashType)request.HashType;
            ContentHash hash         = request.ContentHash.ToContentHash((HashType)request.HashType);

            // Iterate through all known stores, looking for content in each.
            // In most of our configurations there is just one store anyway,
            // and doing this means both we can callers don't have
            // to deal with cache roots and drive letters.

            foreach (KeyValuePair <string, IContentStore> entry in _contentStoreByCacheName)
            {
                IStreamStore store = entry.Value as IStreamStore;
                if (store != null)
                {
                    FileExistenceResult result = await store.CheckFileExistsAsync(cacheContext, hash);

                    if (result.Succeeded)
                    {
                        return(new ExistenceResponse {
                            Header = ResponseHeader.Success(startTime)
                        });
                    }
                }
            }

            return(new ExistenceResponse {
                Header = ResponseHeader.Failure(startTime, $"{hash} not found in the cache")
            });
        }