@@ -15,7 +15,7 @@ namespace BitFaster.Caching.Lru
1515 /// </remarks>
1616 public readonly struct TLruTickCount64Policy < K , V > : IItemPolicy < K , V , LongTickCountLruItem < K , V > >
1717 {
18- private readonly int timeToLive ;
18+ private readonly long timeToLive ;
1919
2020 ///<inheritdoc/>
2121 public TimeSpan TimeToLive => TimeSpan . FromMilliseconds ( timeToLive ) ;
@@ -26,7 +26,13 @@ namespace BitFaster.Caching.Lru
2626 /// <param name="timeToLive">The time to live.</param>
2727 public TLruTickCount64Policy ( TimeSpan timeToLive )
2828 {
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 ;
3036 }
3137
3238 ///<inheritdoc/>
@@ -47,14 +53,14 @@ public void Touch(LongTickCountLruItem<K, V> item)
4753 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
4854 public void Update ( LongTickCountLruItem < K , V > item )
4955 {
50- item . TickCount = Environment . TickCount ;
56+ item . TickCount = Environment . TickCount64 ;
5157 }
5258
5359 ///<inheritdoc/>
5460 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
5561 public bool ShouldDiscard ( LongTickCountLruItem < K , V > item )
5662 {
57- if ( Environment . TickCount - item . TickCount > this . timeToLive )
63+ if ( Environment . TickCount64 - item . TickCount > this . timeToLive )
5864 {
5965 return true ;
6066 }
0 commit comments