aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Controller
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2016-08-06 17:10:18 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2016-08-06 17:10:18 -0400
commit894d87fabb812152c76443afcf1739fda7c578ff (patch)
tree35c5a8ae4581a6857c8b927675671db58bf5d59c /MediaBrowser.Controller
parent7835d3d629a8a39b2830fa906a0479c19b3e6321 (diff)
add file cache
Diffstat (limited to 'MediaBrowser.Controller')
-rw-r--r--MediaBrowser.Controller/Providers/DirectoryService.cs41
1 files changed, 17 insertions, 24 deletions
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<string, Dictionary<string, FileSystemMetadata>> _cache =
new ConcurrentDictionary<string, Dictionary<string, FileSystemMetadata>>(StringComparer.OrdinalIgnoreCase);
- public DirectoryService(ILogger logger, IFileSystem fileSystem)
+ private readonly ConcurrentDictionary<string, FileSystemMetadata> _fileCache =
+ new ConcurrentDictionary<string, FileSystemMetadata>(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<FileSystemMetadata> GetDirectories(string path)