コード例 #1
0
        public async ValueTask <FileInformation> Load(IFile file)
        {
            var root = _fileSystem.Path.GetPathRoot(file.Filename);

            var volumeLock = _driveLocks.GetOrAdd(root, new Lazy <SemaphoreSlim>(() => new SemaphoreSlim(1, 1), LazyThreadSafetyMode.ExecutionAndPublication))
                             .Value;

            Stream fileStream;

            await volumeLock.WaitAsync();

            try
            {
                if (file.Length > _options.LargeFileMargin)
                {
                    return(await _fileInformationLoader.Load(file));
                }

                fileStream = await _fileInformationLoader.LoadFileToMemory(file);
            }
            finally
            {
                volumeLock.Release();
            }

            await using (fileStream)
            {
                return(_fileInformationLoader.Load(file, fileStream));
            }
        }
コード例 #2
0
        public async ValueTask <FileInformation> Load(IFile file)
        {
            if (_cachedResults.TryGetValue(file.Filename, out var fileInformation))
            {
                return(fileInformation);
            }

            var result = await _fileInformationLoader.Load(file);

            _cachedResults.TryAdd(file.Filename, result);

            return(result);
        }