Skip to content

Commit 5ff42a1

Browse files
committed
Fixes in-memory cache compaction logic
Corrects the estimated size check to use -1 for skipped entries. Ensures consistent naming for the maximum removal count constant in the compaction logic. Fixes #399
1 parent 46f9fed commit 5ff42a1

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/Foundatio/Caching/InMemoryCacheClient.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ private async Task<bool> SetInternalAsync(string key, CacheEntry entry, bool add
941941
}
942942

943943
// Check entry size before caching - may throw if ShouldThrowOnMaxEntrySizeExceeded is true
944-
// EstimatedSize returns 0 for entries that should be skipped (logged internally)
944+
// EstimatedSize returns -1 for entries that should be skipped (logged internally)
945945
var entrySize = entry.EstimatedSize;
946946
if (entrySize < 0)
947947
{
@@ -1399,9 +1399,9 @@ private async Task CompactAsync()
13991399
using (await _lock.LockAsync().AnyContext())
14001400
{
14011401
int removalCount = 0;
1402-
const int maxRemovals = 10; // Safety limit to prevent infinite loops
1402+
const int MaxRemovals = 10; // Safety limit to prevent infinite loops
14031403

1404-
while (ShouldCompact && removalCount < maxRemovals)
1404+
while (ShouldCompact && removalCount < MaxRemovals)
14051405
{
14061406
// Check if we still need compaction
14071407
bool needsItemCompaction = _maxItems.HasValue && _memory.Count > _maxItems;

0 commit comments

Comments
 (0)