aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Controller/Providers/DirectoryService.cs
diff options
context:
space:
mode:
authorPatrick Barron <barronpm@gmail.com>2021-05-18 18:09:46 -0400
committerPatrick Barron <barronpm@gmail.com>2021-05-18 18:09:46 -0400
commita225f3479600b511b3a53cfba6d59f6bc3210821 (patch)
treed310a84faaa98851407f990cce7b4f6caf725af3 /MediaBrowser.Controller/Providers/DirectoryService.cs
parent12fa5c0c41c255f4d74d56eacaa38ed2da420d6f (diff)
parent88a7875a2739bef91f1d7216c5ebd89b4c267911 (diff)
Merge branch 'master' into authenticationdb-efcore
# Conflicts: # Jellyfin.Api/Helpers/RequestHelpers.cs
Diffstat (limited to 'MediaBrowser.Controller/Providers/DirectoryService.cs')
-rw-r--r--MediaBrowser.Controller/Providers/DirectoryService.cs25
1 files changed, 12 insertions, 13 deletions
diff --git a/MediaBrowser.Controller/Providers/DirectoryService.cs b/MediaBrowser.Controller/Providers/DirectoryService.cs
index 16fd1d42b..291a26883 100644
--- a/MediaBrowser.Controller/Providers/DirectoryService.cs
+++ b/MediaBrowser.Controller/Providers/DirectoryService.cs
@@ -12,11 +12,11 @@ namespace MediaBrowser.Controller.Providers
{
private readonly IFileSystem _fileSystem;
- private readonly ConcurrentDictionary<string, FileSystemMetadata[]> _cache = new ConcurrentDictionary<string, FileSystemMetadata[]>(StringComparer.OrdinalIgnoreCase);
+ private readonly ConcurrentDictionary<string, FileSystemMetadata[]> _cache = new (StringComparer.Ordinal);
- private readonly ConcurrentDictionary<string, FileSystemMetadata> _fileCache = new ConcurrentDictionary<string, FileSystemMetadata>(StringComparer.OrdinalIgnoreCase);
+ private readonly ConcurrentDictionary<string, FileSystemMetadata> _fileCache = new (StringComparer.Ordinal);
- private readonly ConcurrentDictionary<string, List<string>> _filePathCache = new ConcurrentDictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase);
+ private readonly ConcurrentDictionary<string, List<string>> _filePathCache = new (StringComparer.Ordinal);
public DirectoryService(IFileSystem fileSystem)
{
@@ -43,18 +43,17 @@ namespace MediaBrowser.Controller.Providers
return list;
}
- public FileSystemMetadata GetFile(string path)
+ public FileSystemMetadata? GetFile(string path)
{
- var result = _fileCache.GetOrAdd(path, p =>
+ if (!_fileCache.TryGetValue(path, out var result))
{
- var file = _fileSystem.GetFileInfo(p);
- return file != null && file.Exists ? file : null;
- });
-
- if (result == null)
- {
- // lets not store null results in the cache
- _fileCache.TryRemove(path, out _);
+ var file = _fileSystem.GetFileInfo(path);
+ var res = file != null && file.Exists ? file : null;
+ if (res != null)
+ {
+ result = res;
+ _fileCache.TryAdd(path, result);
+ }
}
return result;