3
3
using HttpClient . Cache . InMemory ;
4
4
5
5
namespace HttpClient . Cache . Tests . InMemory ;
6
-
7
- [ CollectionDefinition ( "Sequential" , DisableParallelization = true ) ]
8
6
public class MemoryCacheTests
9
7
{
10
8
[ Fact ]
11
9
public void CreateEntry_Create10NewEntryAndSetValue_CacheContains10Items ( )
12
10
{
13
11
var expiration = TimeSpan . FromHours ( 1 ) ;
14
- var options = new MemoryCacheOptions ( ) ;
12
+ var options = new MemoryCacheOptions { ExpirationScanFrequency = TimeSpan . FromSeconds ( 1.0 ) } ;
15
13
var cache = new MemoryCache ( options ) ;
16
14
17
15
for ( var i = 1 ; i <= 10 ; ++ i )
@@ -34,18 +32,18 @@ public void CreateEntry_Create10NewEntryAndSetValue_CacheContains10Items()
34
32
[ Fact ]
35
33
public async Task CreateEntry_ExpireAbsoluteExpirationRelativeToNow_CacheIsEmpty ( )
36
34
{
37
- var options = new MemoryCacheOptions ( ) ;
35
+ var options = new MemoryCacheOptions { ExpirationScanFrequency = TimeSpan . FromSeconds ( 1.0 ) } ;
38
36
var cache = new MemoryCache ( options ) ;
39
37
40
38
using ( var entry = cache . CreateEntry ( "key" ) ) {
41
- entry . AbsoluteExpirationRelativeToNow = TimeSpan . FromSeconds ( 3 ) ;
39
+ entry . AbsoluteExpirationRelativeToNow = TimeSpan . FromSeconds ( 2 ) ;
42
40
entry . Value = $ "value";
43
41
}
44
42
45
43
using ( new AssertionScope ( ) )
46
44
{
47
45
cache . Count . Should ( ) . Be ( 1 ) ;
48
- await Task . Delay ( TimeSpan . FromSeconds ( 4 ) ) ;
46
+ await Task . Delay ( TimeSpan . FromSeconds ( 3 ) ) ;
49
47
50
48
var value = cache . TryGetValue ( "key" , out var cacheEntry ) ;
51
49
value . Should ( ) . BeFalse ( ) ;
@@ -58,7 +56,7 @@ public async Task CreateEntry_ExpireAbsoluteExpirationRelativeToNow_CacheIsEmpty
58
56
public async Task CreateEntry_ExpireSlidingExpiration_CacheIsEmpty ( )
59
57
{
60
58
var expiration = TimeSpan . FromSeconds ( 2 ) ;
61
- var options = new MemoryCacheOptions ( ) ;
59
+ var options = new MemoryCacheOptions { ExpirationScanFrequency = TimeSpan . FromSeconds ( 1.0 ) } ;
62
60
var cache = new MemoryCache ( options ) ;
63
61
64
62
using ( var entry = cache . CreateEntry ( "key" ) ) {
@@ -82,7 +80,7 @@ public async Task CreateEntry_ExpireSlidingExpiration_CacheIsEmpty()
82
80
[ Fact ]
83
81
public async Task CreateEntry_ExpireAbsoluteDate_CacheIsEmpty ( )
84
82
{
85
- var options = new MemoryCacheOptions ( ) ;
83
+ var options = new MemoryCacheOptions { ExpirationScanFrequency = TimeSpan . FromSeconds ( 1.0 ) } ;
86
84
var cache = new MemoryCache ( options ) ;
87
85
88
86
using ( var entry = cache . CreateEntry ( "key" ) ) {
0 commit comments