2
2
3
3
namespace System . Linq . Dynamic . Core . Parser
4
4
{
5
- internal class ThreadSafeSlidingCache < T1 , T2 > where T1 : notnull where T2 : notnull
5
+ internal class ThreadSafeSlidingCache < TKey , TValue > where TKey : notnull where TValue : notnull
6
6
{
7
- private readonly ConcurrentDictionary < T1 , ( T2 Value , DateTime ExpirationTime ) > _cache ;
7
+ private readonly ConcurrentDictionary < TKey , ( TValue Value , DateTime ExpirationTime ) > _cache ;
8
8
private readonly TimeSpan _timeToLive ;
9
9
private readonly TimeSpan _cleanupFrequency ;
10
10
private DateTime _lastCleanupTime = DateTime . MinValue ;
11
11
12
12
public ThreadSafeSlidingCache ( TimeSpan timeToLive , TimeSpan ? cleanupFrequency = null )
13
13
{
14
- _cache = new ConcurrentDictionary < T1 , ( T2 , DateTime ) > ( ) ;
14
+ _cache = new ConcurrentDictionary < TKey , ( TValue , DateTime ) > ( ) ;
15
15
_timeToLive = timeToLive ;
16
16
_cleanupFrequency = cleanupFrequency ?? TimeSpan . FromSeconds ( 10 ) ;
17
17
}
18
18
19
19
public TimeSpan TimeToLive => _timeToLive ;
20
20
21
- public void AddOrUpdate ( T1 key , T2 value )
21
+ public void AddOrUpdate ( TKey key , TValue value )
22
22
{
23
23
if ( key == null ) throw new ArgumentNullException ( nameof ( key ) ) ;
24
24
if ( value == null ) throw new ArgumentNullException ( nameof ( value ) ) ;
@@ -29,7 +29,7 @@ public void AddOrUpdate(T1 key, T2 value)
29
29
CleanupIfNeeded ( ) ;
30
30
}
31
31
32
- public bool TryGetValue ( T1 key , out T2 value )
32
+ public bool TryGetValue ( TKey key , out TValue value )
33
33
{
34
34
if ( key == null ) throw new ArgumentNullException ( nameof ( key ) ) ;
35
35
@@ -54,7 +54,7 @@ public bool TryGetValue(T1 key, out T2 value)
54
54
return false ;
55
55
}
56
56
57
- public bool Remove ( T1 key )
57
+ public bool Remove ( TKey key )
58
58
{
59
59
if ( key == null ) throw new ArgumentNullException ( nameof ( key ) ) ;
60
60
var removed = _cache . TryRemove ( key , out _ ) ;
0 commit comments