1
- using Files . Common ;
2
- using System . Collections . Generic ;
1
+ using System . Collections . Concurrent ;
3
2
using System . Threading ;
4
3
using System . Threading . Tasks ;
5
4
@@ -14,40 +13,31 @@ public static FileListCacheController GetInstance()
14
13
return instance ??= new FileListCacheController ( ) ;
15
14
}
16
15
17
- private readonly IFileListCache persistentAdapter ;
18
-
19
16
private FileListCacheController ( )
20
17
{
21
- persistentAdapter = new PersistentSQLiteCacheAdapter ( ) ;
22
18
}
23
19
24
- private readonly Dictionary < string , object > fileNamesCache = new Dictionary < string , object > ( ) ;
20
+ private readonly ConcurrentDictionary < string , string > fileNamesCache = new ConcurrentDictionary < string , string > ( ) ;
25
21
26
- public async Task < string > ReadFileDisplayNameFromCache ( string path , CancellationToken cancellationToken )
22
+ public Task < string > ReadFileDisplayNameFromCache ( string path , CancellationToken cancellationToken )
27
23
{
28
- var displayName = fileNamesCache . Get ( path , ( string ) null ) ;
29
- if ( displayName == null )
24
+ if ( fileNamesCache . TryGetValue ( path , out var displayName ) )
30
25
{
31
- displayName = await persistentAdapter . ReadFileDisplayNameFromCache ( path , cancellationToken ) ;
32
- if ( displayName != null )
33
- {
34
- fileNamesCache [ path ] = displayName ;
35
- }
26
+ return Task . FromResult ( displayName ) ;
36
27
}
37
- return displayName ;
28
+
29
+ return Task . FromResult < string > ( null ) ;
38
30
}
39
31
40
32
public Task SaveFileDisplayNameToCache ( string path , string displayName )
41
33
{
42
34
if ( displayName == null )
43
35
{
44
- fileNamesCache . Remove ( path ) ;
45
- return persistentAdapter . SaveFileDisplayNameToCache ( path , displayName ) ;
36
+ fileNamesCache . TryRemove ( path , out _ ) ;
46
37
}
47
- fileNamesCache [ path ] = displayName ;
48
38
49
- // save entry to persistent cache in background
50
- return persistentAdapter . SaveFileDisplayNameToCache ( path , displayName ) ;
39
+ fileNamesCache [ path ] = displayName ;
40
+ return Task . CompletedTask ;
51
41
}
52
42
}
53
43
}
0 commit comments