forked from files-community/Files
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileListCacheController.cs
43 lines (35 loc) · 1.21 KB
/
FileListCacheController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;
namespace Files.Helpers.FileListCache
{
internal class FileListCacheController : IFileListCache
{
private static FileListCacheController instance;
public static FileListCacheController GetInstance()
{
return instance ??= new FileListCacheController();
}
private FileListCacheController()
{
}
private readonly ConcurrentDictionary<string, string> fileNamesCache = new ConcurrentDictionary<string, string>();
public Task<string> ReadFileDisplayNameFromCache(string path, CancellationToken cancellationToken)
{
if (fileNamesCache.TryGetValue(path, out var displayName))
{
return Task.FromResult(displayName);
}
return Task.FromResult<string>(null);
}
public Task SaveFileDisplayNameToCache(string path, string displayName)
{
if (displayName == null)
{
fileNamesCache.TryRemove(path, out _);
}
fileNamesCache[path] = displayName;
return Task.CompletedTask;
}
}
}