@@ -66,7 +66,7 @@ public void WhenItemsAddedExceedsCapacityItemsAreDiscarded()
66
66
cache . GetOrAdd ( i , k => k ) ;
67
67
}
68
68
69
- cache . PendingMaintenance ( ) ;
69
+ cache . DoMaintenance ( ) ;
70
70
LogLru ( ) ;
71
71
72
72
cache . Count . Should ( ) . Be ( 20 ) ;
@@ -84,7 +84,7 @@ public void WhenItemIsEvictedItIsDisposed()
84
84
dcache . GetOrAdd ( i , k => disposables [ i ] ) ;
85
85
}
86
86
87
- dcache . PendingMaintenance ( ) ;
87
+ dcache . DoMaintenance ( ) ;
88
88
LogLru ( ) ;
89
89
90
90
dcache . Count . Should ( ) . Be ( 20 ) ;
@@ -103,7 +103,7 @@ public void WhenNewItemsAreAddedTheyArePromotedBasedOnFrequency()
103
103
}
104
104
105
105
// W [19] Protected [] Probation [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18]
106
- cache . PendingMaintenance ( ) ;
106
+ cache . DoMaintenance ( ) ;
107
107
LogLru ( ) ;
108
108
109
109
for ( int i = 0 ; i < 15 ; i ++ )
@@ -112,7 +112,7 @@ public void WhenNewItemsAreAddedTheyArePromotedBasedOnFrequency()
112
112
}
113
113
114
114
// W [19] Protected [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14] Probation [15,16,17,18]
115
- cache . PendingMaintenance ( ) ;
115
+ cache . DoMaintenance ( ) ;
116
116
LogLru ( ) ;
117
117
118
118
for ( int k = 0 ; k < 2 ; k ++ )
@@ -123,7 +123,7 @@ public void WhenNewItemsAreAddedTheyArePromotedBasedOnFrequency()
123
123
{
124
124
cache . GetOrAdd ( j + 20 , k => k ) ;
125
125
}
126
- cache . PendingMaintenance ( ) ;
126
+ cache . DoMaintenance ( ) ;
127
127
LogLru ( ) ;
128
128
}
129
129
}
@@ -145,7 +145,7 @@ public void WhenNewItemsAreAddedTheyArePromotedBasedOnFrequency()
145
145
146
146
// W [24] Protected [5,6,7,8,9,10,11,12,13,14,20,21,22,23,25] Probation []
147
147
cache . Trim ( 4 ) ;
148
- cache . PendingMaintenance ( ) ;
148
+ cache . DoMaintenance ( ) ;
149
149
LogLru ( ) ;
150
150
151
151
cache . TryGet ( 1 , out var value1 ) . Should ( ) . BeFalse ( ) ;
@@ -162,12 +162,12 @@ public void ReadPromotesProbation()
162
162
}
163
163
164
164
// W [19] Protected [] Probation [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18]
165
- cache . PendingMaintenance ( ) ;
165
+ cache . DoMaintenance ( ) ;
166
166
LogLru ( ) ;
167
167
168
168
// W [19] Protected [16] Probation [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,17,18]
169
169
cache . GetOrAdd ( 16 , k => k ) ;
170
- cache . PendingMaintenance ( ) ;
170
+ cache . DoMaintenance ( ) ;
171
171
LogLru ( ) ;
172
172
173
173
for ( int i = 25 ; i < 50 ; i ++ )
@@ -177,13 +177,13 @@ public void ReadPromotesProbation()
177
177
}
178
178
179
179
// W [49] Protected [16] Probation [25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42]
180
- cache . PendingMaintenance ( ) ;
180
+ cache . DoMaintenance ( ) ;
181
181
LogLru ( ) ;
182
182
183
183
cache . Trim ( 18 ) ;
184
184
185
185
// W [49] Protected [16] Probation []
186
- cache . PendingMaintenance ( ) ;
186
+ cache . DoMaintenance ( ) ;
187
187
LogLru ( ) ;
188
188
189
189
cache . TryGet ( 16 , out var value1 ) . Should ( ) . BeTrue ( ) ;
@@ -199,12 +199,12 @@ public void WritePromotesProbation()
199
199
}
200
200
201
201
// W [19] Protected [] Probation [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18]
202
- cache . PendingMaintenance ( ) ;
202
+ cache . DoMaintenance ( ) ;
203
203
LogLru ( ) ;
204
204
205
205
// W [24] Protected [16] Probation [2,6,7,8,9,10,11,12,13,14,15,17,18,19,20,21,22,23]
206
206
cache . TryUpdate ( 16 , - 16 ) . Should ( ) . BeTrue ( ) ;
207
- cache . PendingMaintenance ( ) ;
207
+ cache . DoMaintenance ( ) ;
208
208
LogLru ( ) ;
209
209
210
210
for ( int i = 25 ; i < 50 ; i ++ )
@@ -214,13 +214,13 @@ public void WritePromotesProbation()
214
214
}
215
215
216
216
// W [49] Protected [16] Probation [2,6,7,8,9,10,11,12,13,14,15,17,18,19,20,21,22,23]
217
- cache . PendingMaintenance ( ) ;
217
+ cache . DoMaintenance ( ) ;
218
218
LogLru ( ) ;
219
219
220
220
cache . Trim ( 18 ) ;
221
221
222
222
// W [49] Protected [16] Probation []
223
- cache . PendingMaintenance ( ) ;
223
+ cache . DoMaintenance ( ) ;
224
224
LogLru ( ) ;
225
225
226
226
cache . TryGet ( 16 , out var value1 ) . Should ( ) . BeTrue ( ) ;
@@ -235,27 +235,27 @@ public void ReadUpdatesProtectedLruOrder()
235
235
cache . GetOrAdd ( i , k => k ) ;
236
236
}
237
237
238
- cache . PendingMaintenance ( ) ;
238
+ cache . DoMaintenance ( ) ;
239
239
LogLru ( ) ;
240
240
241
241
cache . GetOrAdd ( 7 , k => k ) ;
242
242
cache . GetOrAdd ( 8 , k => k ) ;
243
243
cache . GetOrAdd ( 9 , k => k ) ;
244
244
245
245
// W [19] Protected [7,8,9] Probation [0,1,2,3,4,5,6,10,11,12,13,14,15,16,17,18]
246
- cache . PendingMaintenance ( ) ;
246
+ cache . DoMaintenance ( ) ;
247
247
LogLru ( ) ;
248
248
249
249
// W [19] Protected [8,9,7] Probation [0,1,2,3,4,5,6,10,11,12,13,14,15,16,17,18]
250
250
// element 7 now moved to back of LRU
251
251
cache . GetOrAdd ( 7 , k => k ) ;
252
- cache . PendingMaintenance ( ) ;
252
+ cache . DoMaintenance ( ) ;
253
253
LogLru ( ) ;
254
254
255
255
// Trim is LRU order
256
256
//W [19] Protected [7] Probation []
257
257
cache . Trim ( 18 ) ;
258
- cache . PendingMaintenance ( ) ;
258
+ cache . DoMaintenance ( ) ;
259
259
LogLru ( ) ;
260
260
261
261
cache . TryGet ( 7 , out var _ ) . Should ( ) . BeTrue ( ) ;
@@ -270,27 +270,27 @@ public void WriteUpdatesProtectedLruOrder()
270
270
cache . GetOrAdd ( i , k => k ) ;
271
271
}
272
272
273
- cache . PendingMaintenance ( ) ;
273
+ cache . DoMaintenance ( ) ;
274
274
LogLru ( ) ;
275
275
276
276
cache . GetOrAdd ( 7 , k => k ) ;
277
277
cache . GetOrAdd ( 8 , k => k ) ;
278
278
cache . GetOrAdd ( 9 , k => k ) ;
279
279
280
280
// W [19] Protected [7,8,9] Probation [0,1,2,3,4,5,6,10,11,12,13,14,15,16,17,18]
281
- cache . PendingMaintenance ( ) ;
281
+ cache . DoMaintenance ( ) ;
282
282
LogLru ( ) ;
283
283
284
284
// W [19] Protected [8,9,7] Probation [0,1,2,3,4,5,6,10,11,12,13,14,15,16,17,18]
285
285
// element 7 now moved to back of LRU
286
286
cache . TryUpdate ( 7 , - 7 ) . Should ( ) . BeTrue ( ) ;
287
- cache . PendingMaintenance ( ) ;
287
+ cache . DoMaintenance ( ) ;
288
288
LogLru ( ) ;
289
289
290
290
// Trim is LRU order
291
291
//W [19] Protected [7] Probation []
292
292
cache . Trim ( 18 ) ;
293
- cache . PendingMaintenance ( ) ;
293
+ cache . DoMaintenance ( ) ;
294
294
LogLru ( ) ;
295
295
296
296
cache . TryGet ( 7 , out var _ ) . Should ( ) . BeTrue ( ) ;
@@ -308,7 +308,7 @@ public void WhenHitRateChangesWindowSizeIsAdapted()
308
308
}
309
309
310
310
// W [19] Protected [] Probation [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18]
311
- cache . PendingMaintenance ( ) ;
311
+ cache . DoMaintenance ( ) ;
312
312
LogLru ( ) ;
313
313
314
314
for ( int i = 0 ; i < 15 ; i ++ )
@@ -317,7 +317,7 @@ public void WhenHitRateChangesWindowSizeIsAdapted()
317
317
}
318
318
319
319
// W [19] Protected [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14] Probation [15,16,17,18]
320
- cache . PendingMaintenance ( ) ;
320
+ cache . DoMaintenance ( ) ;
321
321
LogLru ( ) ;
322
322
323
323
// The reset sample size is 200, so do 200 cache hits
@@ -328,7 +328,7 @@ public void WhenHitRateChangesWindowSizeIsAdapted()
328
328
cache . GetOrAdd ( i , k => k ) ;
329
329
}
330
330
331
- cache . PendingMaintenance ( ) ;
331
+ cache . DoMaintenance ( ) ;
332
332
LogLru ( ) ;
333
333
334
334
// then miss 200 times
@@ -338,7 +338,7 @@ public void WhenHitRateChangesWindowSizeIsAdapted()
338
338
cache . GetOrAdd ( i + 100 , k => k ) ;
339
339
}
340
340
341
- cache . PendingMaintenance ( ) ;
341
+ cache . DoMaintenance ( ) ;
342
342
LogLru ( ) ;
343
343
344
344
// then miss 200 more times (window adaptation +1 window slots)
@@ -348,14 +348,14 @@ public void WhenHitRateChangesWindowSizeIsAdapted()
348
348
cache . GetOrAdd ( i + 200 , k => k ) ;
349
349
}
350
350
351
- cache . PendingMaintenance ( ) ;
351
+ cache . DoMaintenance ( ) ;
352
352
LogLru ( ) ;
353
353
354
354
// make 2 requests to new keys, if window is size is now 2 both will exist:
355
355
cache . GetOrAdd ( 666 , k => k ) ;
356
356
cache . GetOrAdd ( 667 , k => k ) ;
357
357
358
- cache . PendingMaintenance ( ) ;
358
+ cache . DoMaintenance ( ) ;
359
359
LogLru ( ) ;
360
360
361
361
cache . TryGet ( 666 , out var _ ) . Should ( ) . BeTrue ( ) ;
@@ -372,7 +372,7 @@ public void ReadSchedulesMaintenanceWhenBufferIsFull()
372
372
373
373
cache . GetOrAdd ( 1 , k => k ) ;
374
374
scheduler . RunCount . Should ( ) . Be ( 1 ) ;
375
- cache . PendingMaintenance ( ) ;
375
+ cache . DoMaintenance ( ) ;
376
376
377
377
for ( int i = 0 ; i < ConcurrentLfu < int , int > . DefaultBufferSize ; i ++ )
378
378
{
@@ -393,14 +393,14 @@ public void WhenReadBufferIsFullReadsAreDropped()
393
393
394
394
cache . GetOrAdd ( 1 , k => k ) ;
395
395
scheduler . RunCount . Should ( ) . Be ( 1 ) ;
396
- cache . PendingMaintenance ( ) ;
396
+ cache . DoMaintenance ( ) ;
397
397
398
398
for ( int i = 0 ; i < ConcurrentLfu < int , int > . DefaultBufferSize * 2 ; i ++ )
399
399
{
400
400
cache . GetOrAdd ( 1 , k => k ) ;
401
401
}
402
402
403
- cache . PendingMaintenance ( ) ;
403
+ cache . DoMaintenance ( ) ;
404
404
405
405
cache . Metrics . Value . Hits . Should ( ) . Be ( ConcurrentLfu < int , int > . DefaultBufferSize ) ;
406
406
}
@@ -415,7 +415,7 @@ public void WhenWriteBufferIsFullAddDoesMaintenance()
415
415
416
416
// add an item, flush write buffer
417
417
cache . GetOrAdd ( - 1 , k => k ) ;
418
- cache . PendingMaintenance ( ) ;
418
+ cache . DoMaintenance ( ) ;
419
419
420
420
// remove the item but don't flush, it is now in the write buffer and maintenance is scheduled
421
421
cache . TryRemove ( - 1 ) . Should ( ) . BeTrue ( ) ;
@@ -442,14 +442,14 @@ public void WhenWriteBufferIsFullUpdatesAreDropped()
442
442
443
443
cache . GetOrAdd ( 1 , k => k ) ;
444
444
scheduler . RunCount . Should ( ) . Be ( 1 ) ;
445
- cache . PendingMaintenance ( ) ;
445
+ cache . DoMaintenance ( ) ;
446
446
447
447
for ( int i = 0 ; i < bufferSize * 2 ; i ++ )
448
448
{
449
449
cache . TryUpdate ( 1 , i ) ;
450
450
}
451
451
452
- cache . PendingMaintenance ( ) ;
452
+ cache . DoMaintenance ( ) ;
453
453
454
454
cache . Metrics . Value . Updated . Should ( ) . Be ( bufferSize ) ;
455
455
}
@@ -484,7 +484,7 @@ public void WhenItemIsAddedThenRetrievedMetricHitRatioIsHalf()
484
484
cache . GetOrAdd ( 1 , k => k ) ;
485
485
bool result = cache . TryGet ( 1 , out var value ) ;
486
486
487
- cache . PendingMaintenance ( ) ;
487
+ cache . DoMaintenance ( ) ;
488
488
489
489
cache . Metrics . Value . HitRatio . Should ( ) . Be ( 0.5 ) ;
490
490
cache . Metrics . Value . Hits . Should ( ) . Be ( 1 ) ;
@@ -504,7 +504,7 @@ public void WhenItemIsEvictedMetricRecordsCount()
504
504
cache . GetOrAdd ( i , k => k ) ;
505
505
}
506
506
507
- cache . PendingMaintenance ( ) ;
507
+ cache . DoMaintenance ( ) ;
508
508
509
509
cache . Metrics . Value . Evicted . Should ( ) . Be ( 5 ) ;
510
510
}
@@ -576,7 +576,7 @@ public void WhenItemIsRemovedItIsDisposed()
576
576
dcache . GetOrAdd ( 1 , k => disposable ) ;
577
577
578
578
dcache . TryRemove ( 1 ) . Should ( ) . BeTrue ( ) ;
579
- dcache . PendingMaintenance ( ) ;
579
+ dcache . DoMaintenance ( ) ;
580
580
581
581
disposable . IsDisposed . Should ( ) . BeTrue ( ) ;
582
582
}
@@ -587,7 +587,7 @@ public void WhenItemIsRemovedEvictionCountIsIncremented()
587
587
cache . GetOrAdd ( 1 , k => k ) ;
588
588
589
589
cache . TryRemove ( 1 ) . Should ( ) . BeTrue ( ) ;
590
- cache . PendingMaintenance ( ) ;
590
+ cache . DoMaintenance ( ) ;
591
591
592
592
cache . Metrics . Value . Evicted . Should ( ) . Be ( 1 ) ;
593
593
}
@@ -605,15 +605,15 @@ public void WhenRemovedInWriteBuffer()
605
605
cache . GetOrAdd ( 1 , k => k ) ;
606
606
607
607
// wait for the maintenance thread to run, this will attach the new node to the LRU list
608
- cache . PendingMaintenance ( ) ;
608
+ cache . DoMaintenance ( ) ;
609
609
610
610
// pending write in the buffer
611
611
cache . TryUpdate ( 1 , 2 ) ;
612
612
613
613
// immediately remove
614
614
cache . TryRemove ( 1 ) . Should ( ) . BeTrue ( ) ;
615
615
616
- cache . PendingMaintenance ( ) ;
616
+ cache . DoMaintenance ( ) ;
617
617
618
618
cache . TryGet ( 1 , out var _ ) . Should ( ) . BeFalse ( ) ;
619
619
}
@@ -629,10 +629,10 @@ public void WhenClearedCacheIsEmpty()
629
629
{
630
630
cache . GetOrAdd ( 1 , k => k ) ;
631
631
cache . GetOrAdd ( 2 , k => k ) ;
632
- cache . PendingMaintenance ( ) ;
632
+ cache . DoMaintenance ( ) ;
633
633
634
634
cache . Clear ( ) ;
635
- cache . PendingMaintenance ( ) ;
635
+ cache . DoMaintenance ( ) ;
636
636
637
637
cache . Count . Should ( ) . Be ( 0 ) ;
638
638
cache . TryGet ( 1 , out var _ ) . Should ( ) . BeFalse ( ) ;
@@ -645,12 +645,12 @@ public void TrimRemovesNItems()
645
645
{
646
646
cache . GetOrAdd ( i , k => k ) ;
647
647
}
648
- cache . PendingMaintenance ( ) ;
648
+ cache . DoMaintenance ( ) ;
649
649
650
650
cache . Count . Should ( ) . Be ( 20 ) ;
651
651
652
652
cache . Trim ( 5 ) ;
653
- cache . PendingMaintenance ( ) ;
653
+ cache . DoMaintenance ( ) ;
654
654
655
655
cache . Count . Should ( ) . Be ( 15 ) ;
656
656
}
@@ -669,7 +669,7 @@ public void TrimWhileItemsInWriteBufferRemovesNItems()
669
669
// Trim implicitly performs maintenance
670
670
cache . Trim ( 5 ) ;
671
671
672
- cache . PendingMaintenance ( ) ;
672
+ cache . DoMaintenance ( ) ;
673
673
674
674
// The trim takes effect before all the writes are replayed by the maintenance thread.
675
675
cache . Metrics . Value . Evicted . Should ( ) . Be ( 10 ) ;
@@ -747,7 +747,7 @@ public void VerifyMisses()
747
747
748
748
var end = Stopwatch . GetTimestamp ( ) ;
749
749
750
- cache . PendingMaintenance ( ) ;
750
+ cache . DoMaintenance ( ) ;
751
751
752
752
var totalTicks = end - start ;
753
753
var timeMs = ( ( double ) totalTicks / Stopwatch . Frequency ) * 1000.0 ;
0 commit comments