From 894d87fabb812152c76443afcf1739fda7c578ff Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 6 Aug 2016 17:10:18 -0400 Subject: add file cache --- .../Providers/DirectoryService.cs | 41 +++++++++------------- 1 file changed, 17 insertions(+), 24 deletions(-) (limited to 'MediaBrowser.Controller') diff --git a/MediaBrowser.Controller/Providers/DirectoryService.cs b/MediaBrowser.Controller/Providers/DirectoryService.cs index ca9038439..ee2b28c60 100644 --- a/MediaBrowser.Controller/Providers/DirectoryService.cs +++ b/MediaBrowser.Controller/Providers/DirectoryService.cs @@ -16,7 +16,10 @@ namespace MediaBrowser.Controller.Providers private readonly ConcurrentDictionary> _cache = new ConcurrentDictionary>(StringComparer.OrdinalIgnoreCase); - public DirectoryService(ILogger logger, IFileSystem fileSystem) + private readonly ConcurrentDictionary _fileCache = + new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); + + public DirectoryService(ILogger logger, IFileSystem fileSystem) { _logger = logger; _fileSystem = fileSystem; @@ -100,29 +103,19 @@ namespace MediaBrowser.Controller.Providers public FileSystemMetadata GetFile(string path) { - return _fileSystem.GetFileInfo(path); - //var directory = Path.GetDirectoryName(path); - - //if (string.IsNullOrWhiteSpace(directory)) - //{ - // _logger.Debug("Parent path is null for {0}", path); - // return null; - //} - - //try - //{ - // var dict = GetFileSystemDictionary(directory, false); - - // FileSystemMetadata entry; - // dict.TryGetValue(path, out entry); - - // return entry; - //} - //catch (Exception ex) - //{ - // _logger.ErrorException("Error in GetFileSystemDictionary. Directory: :{0}. Original path: {1}", ex, directory, path); - // return null; - //} + FileSystemMetadata file; + if (!_fileCache.TryGetValue(path, out file)) + { + file = _fileSystem.GetFileInfo(path); + + if (file != null) + { + _fileCache.TryAdd(path, file); + } + } + + return file; + //return _fileSystem.GetFileInfo(path); } public IEnumerable GetDirectories(string path) -- cgit v1.2.3