diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2017-11-05 16:51:23 -0500 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2017-11-05 16:51:23 -0500 |
| commit | 5cb74690284105db70a467ab77c2af3f44e42348 (patch) | |
| tree | 0e37b05d34dbcbe3d08d0c74229287cd0cd6f496 /MediaBrowser.Controller/Providers/DirectoryService.cs | |
| parent | b9c1f61681de23d95de7c6b392eb3e55670991da (diff) | |
support track selection before playback
Diffstat (limited to 'MediaBrowser.Controller/Providers/DirectoryService.cs')
| -rw-r--r-- | MediaBrowser.Controller/Providers/DirectoryService.cs | 52 |
1 files changed, 28 insertions, 24 deletions
diff --git a/MediaBrowser.Controller/Providers/DirectoryService.cs b/MediaBrowser.Controller/Providers/DirectoryService.cs index d957470d3..d673198fd 100644 --- a/MediaBrowser.Controller/Providers/DirectoryService.cs +++ b/MediaBrowser.Controller/Providers/DirectoryService.cs @@ -14,11 +14,11 @@ namespace MediaBrowser.Controller.Providers private readonly ILogger _logger; private readonly IFileSystem _fileSystem; - private readonly ConcurrentDictionary<string, FileSystemMetadata[]> _cache = - new ConcurrentDictionary<string, FileSystemMetadata[]>(StringComparer.OrdinalIgnoreCase); + private readonly Dictionary<string, FileSystemMetadata[]> _cache = new Dictionary<string, FileSystemMetadata[]>(StringComparer.OrdinalIgnoreCase); - private readonly ConcurrentDictionary<string, FileSystemMetadata> _fileCache = - new ConcurrentDictionary<string, FileSystemMetadata>(StringComparer.OrdinalIgnoreCase); + private readonly Dictionary<string, FileSystemMetadata> _fileCache = new Dictionary<string, FileSystemMetadata>(StringComparer.OrdinalIgnoreCase); + + private readonly Dictionary<string, List<string>> _filePathCache = new Dictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase); public DirectoryService(ILogger logger, IFileSystem fileSystem) { @@ -33,11 +33,6 @@ namespace MediaBrowser.Controller.Providers public FileSystemMetadata[] GetFileSystemEntries(string path) { - return GetFileSystemEntries(path, false); - } - - private FileSystemMetadata[] GetFileSystemEntries(string path, bool clearCache) - { if (string.IsNullOrWhiteSpace(path)) { throw new ArgumentNullException("path"); @@ -45,13 +40,6 @@ namespace MediaBrowser.Controller.Providers FileSystemMetadata[] entries; - if (clearCache) - { - FileSystemMetadata[] removed; - - _cache.TryRemove(path, out removed); - } - if (!_cache.TryGetValue(path, out entries)) { //_logger.Debug("Getting files for " + path); @@ -66,7 +54,8 @@ namespace MediaBrowser.Controller.Providers entries = new FileSystemMetadata[] { }; } - _cache.TryAdd(path, entries); + //_cache.TryAdd(path, entries); + _cache[path] = entries; } return entries; @@ -74,13 +63,8 @@ namespace MediaBrowser.Controller.Providers public List<FileSystemMetadata> GetFiles(string path) { - return GetFiles(path, false); - } - - public List<FileSystemMetadata> GetFiles(string path, bool clearCache) - { var list = new List<FileSystemMetadata>(); - var items = GetFileSystemEntries(path, clearCache); + var items = GetFileSystemEntries(path); foreach (var item in items) { if (!item.IsDirectory) @@ -100,7 +84,8 @@ namespace MediaBrowser.Controller.Providers if (file != null && file.Exists) { - _fileCache.TryAdd(path, file); + //_fileCache.TryAdd(path, file); + _fileCache[path] = file; } else { @@ -111,5 +96,24 @@ namespace MediaBrowser.Controller.Providers return file; //return _fileSystem.GetFileInfo(path); } + + public List<string> GetFilePaths(string path) + { + return GetFilePaths(path, false); + } + + public List<string> GetFilePaths(string path, bool clearCache) + { + List<string> result; + if (clearCache || !_filePathCache.TryGetValue(path, out result)) + { + result = _fileSystem.GetFilePaths(path).ToList(); + + _filePathCache[path] = result; + } + + return result; + } + } } |
