@@ -15,7 +15,7 @@ namespace BitFaster.Caching.Lru
15
15
/// </remarks>
16
16
public readonly struct TLruTickCount64Policy < K , V > : IItemPolicy < K , V , LongTickCountLruItem < K , V > >
17
17
{
18
- private readonly int timeToLive ;
18
+ private readonly long timeToLive ;
19
19
20
20
///<inheritdoc/>
21
21
public TimeSpan TimeToLive => TimeSpan . FromMilliseconds ( timeToLive ) ;
@@ -26,7 +26,13 @@ namespace BitFaster.Caching.Lru
26
26
/// <param name="timeToLive">The time to live.</param>
27
27
public TLruTickCount64Policy ( TimeSpan timeToLive )
28
28
{
29
- this . timeToLive = ( int ) timeToLive . TotalMilliseconds ;
29
+ TimeSpan maxRepresentable = TimeSpan . FromTicks ( 9223372036854769664 ) ;
30
+ if ( timeToLive < TimeSpan . Zero || timeToLive > maxRepresentable )
31
+ {
32
+ Ex . ThrowArgOutOfRange ( nameof ( timeToLive ) , $ "Value must greater than zero and less than { maxRepresentable } ") ;
33
+ }
34
+
35
+ this . timeToLive = ( long ) timeToLive . TotalMilliseconds ;
30
36
}
31
37
32
38
///<inheritdoc/>
@@ -47,14 +53,14 @@ public void Touch(LongTickCountLruItem<K, V> item)
47
53
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
48
54
public void Update ( LongTickCountLruItem < K , V > item )
49
55
{
50
- item . TickCount = Environment . TickCount ;
56
+ item . TickCount = Environment . TickCount64 ;
51
57
}
52
58
53
59
///<inheritdoc/>
54
60
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
55
61
public bool ShouldDiscard ( LongTickCountLruItem < K , V > item )
56
62
{
57
- if ( Environment . TickCount - item . TickCount > this . timeToLive )
63
+ if ( Environment . TickCount64 - item . TickCount > this . timeToLive )
58
64
{
59
65
return true ;
60
66
}
0 commit comments