File tree Expand file tree Collapse file tree 6 files changed +11
-23
lines changed
BitFaster.Caching.UnitTests/Lru Expand file tree Collapse file tree 6 files changed +11
-23
lines changed Original file line number Diff line number Diff line change @@ -33,13 +33,8 @@ public void WhenTtlIsZeroThrow()
33
33
[ Fact ]
34
34
public void WhenTtlIsMaxSetAsMax ( )
35
35
{
36
- #if NETFRAMEWORK
37
- var maxRepresentable = TimeSpan . FromTicks ( ( long ) ( long . MaxValue / 100.0d ) ) - TimeSpan . FromTicks ( 10 ) ;
38
- #else
39
- var maxRepresentable = Time . MaxRepresentable ;
40
- #endif
41
- var policy = new AfterAccessPolicy < int , int > ( maxRepresentable ) ;
42
- policy . TimeToLive . Should ( ) . BeCloseTo ( maxRepresentable , TimeSpan . FromTicks ( 20 ) ) ;
36
+ var policy = new AfterAccessPolicy < int , int > ( Duration . MaxRepresentable ) ;
37
+ policy . TimeToLive . Should ( ) . BeCloseTo ( Duration . MaxRepresentable , TimeSpan . FromMilliseconds ( 20 ) ) ;
43
38
}
44
39
45
40
[ Fact ]
Original file line number Diff line number Diff line change @@ -32,9 +32,8 @@ public void WhenTtlIsZeroThrow()
32
32
[ Fact ]
33
33
public void WhenTtlIsMaxSetAsMax ( )
34
34
{
35
- var maxRepresentable = TimeSpan . FromTicks ( 9223372036854769664 ) ;
36
- var policy = new TLruLongTicksPolicy < int , int > ( maxRepresentable ) ;
37
- policy . TimeToLive . Should ( ) . Be ( maxRepresentable ) ;
35
+ var policy = new TLruLongTicksPolicy < int , int > ( Duration . MaxRepresentable ) ;
36
+ policy . TimeToLive . Should ( ) . BeCloseTo ( Duration . MaxRepresentable , TimeSpan . FromMilliseconds ( 20 ) ) ;
38
37
}
39
38
40
39
[ Fact ]
Original file line number Diff line number Diff line change @@ -18,13 +18,11 @@ namespace BitFaster.Caching
18
18
public readonly struct Duration
19
19
{
20
20
internal readonly long raw ;
21
- #if NETCOREAPP3_0_OR_GREATER
22
- internal static readonly TimeSpan MaxRepresentable = TimeSpan . FromTicks ( 9223372036854769664 ) ;
23
- #else
21
+
24
22
// MacOS Stopwatch adjustment factor is 100, giving lowest maximum TTL on mac platform - use same upper limit on all platforms for consistency
25
23
// this also avoids overflow when multipling long.MaxValue by 1.0
26
- internal static readonly TimeSpan MaxRepresentable = TimeSpan . FromTicks ( ( long ) ( long . MaxValue * 0.01d ) ) ;
27
- #endif
24
+ internal static readonly TimeSpan MaxRepresentable = TimeSpan . FromTicks ( ( long ) ( long . MaxValue / 100.0d ) ) ;
25
+
28
26
internal Duration ( long raw )
29
27
{
30
28
this . raw = raw ;
Original file line number Diff line number Diff line change @@ -20,8 +20,8 @@ namespace BitFaster.Caching.Lru
20
20
/// <param name="timeToLive">The time to live.</param>
21
21
public AfterAccessPolicy ( TimeSpan timeToLive )
22
22
{
23
- if ( timeToLive <= TimeSpan . Zero || timeToLive > Time . MaxRepresentable )
24
- Throw . ArgOutOfRange ( nameof ( timeToLive ) , $ "Value must greater than zero and less than { Time . MaxRepresentable } ") ;
23
+ if ( timeToLive <= TimeSpan . Zero || timeToLive > Duration . MaxRepresentable )
24
+ Throw . ArgOutOfRange ( nameof ( timeToLive ) , $ "Value must greater than zero and less than { Duration . MaxRepresentable } ") ;
25
25
26
26
this . timeToLive = Duration . FromTimeSpan ( timeToLive ) ;
27
27
this . time = new Time ( ) ;
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ namespace BitFaster.Caching.Lru
20
20
/// <param name="timeToLive">The time to live.</param>
21
21
public TLruLongTicksPolicy ( TimeSpan timeToLive )
22
22
{
23
- if ( timeToLive <= TimeSpan . Zero || timeToLive > Time . MaxRepresentable )
23
+ if ( timeToLive <= TimeSpan . Zero || timeToLive > Duration . MaxRepresentable )
24
24
Throw . ArgOutOfRange ( nameof ( timeToLive ) , $ "Value must greater than zero and less than { Duration . MaxRepresentable } ") ;
25
25
26
26
this . timeToLive = Duration . FromTimeSpan ( timeToLive ) ;
Original file line number Diff line number Diff line change 1
- using System ;
2
-
3
- namespace BitFaster . Caching . Lru
1
+ namespace BitFaster . Caching . Lru
4
2
{
5
3
/// <summary>
6
4
/// During reads, the policy evaluates ShouldDiscard and Touch. To avoid Getting the current time twice
@@ -9,8 +7,6 @@ namespace BitFaster.Caching.Lru
9
7
/// </summary>
10
8
internal class Time
11
9
{
12
- internal static readonly TimeSpan MaxRepresentable = TimeSpan . FromTicks ( 9223372036854769664 ) ;
13
-
14
10
/// <summary>
15
11
/// Gets or sets the last time.
16
12
/// </summary>
You can’t perform that action at this time.
0 commit comments