Skip to content

Commit b693e35

Browse files
committed
Move expired check to before reference check as we don't care about references until it is actually expired
1 parent 68eeec8 commit b693e35

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

AsyncMemoryCache/EvictionBehaviors/DefaultEvictionBehavior.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ private static async Task CheckExpiredItems<TKey, TValue>(IAsyncMemoryCacheConfi
8585
var cache = configuration.CacheBackingStore;
8686
foreach (var item in cache.Values)
8787
{
88+
if (item.ExpirationStrategy?.IsExpired() is not true)
89+
continue;
90+
8891
if (Interlocked.Decrement(ref item.References) >= 0)
8992
{
9093
// Need to increment again to restore the refcounter
@@ -94,9 +97,6 @@ private static async Task CheckExpiredItems<TKey, TValue>(IAsyncMemoryCacheConfi
9497
continue;
9598
}
9699

97-
if (!(item.ExpirationStrategy?.IsExpired() ?? false))
98-
continue;
99-
100100
expiredItems.Add(item);
101101
}
102102

0 commit comments

Comments
 (0)