Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Commit 1d1622d

Browse files
committed
Run in background thread
1 parent fa45aac commit 1d1622d

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

Diff for: src/Microsoft.Extensions.Caching.Memory/MemoryCache.cs

+12-9
Original file line numberDiff line numberDiff line change
@@ -290,16 +290,19 @@ private void TriggerOvercapacityCompaction()
290290
return;
291291
}
292292

293-
try
293+
Task.Run(_ =>
294294
{
295-
// Keep compacting until remaining entries are at 90% of maximum
296-
// Stop compacting if no entries were removed, for example if all the remaining entries are pinned with NeverRemove priority
297-
while (Compact(1 - ((0.9 * _entryCountLimit.Value) / _entries.Count)) && _entries.Count > _entryCountLimit.Value) { }
298-
}
299-
finally
300-
{
301-
_compactionSemaphore.Release();
302-
}
295+
try
296+
{
297+
// Keep compacting until remaining entries are at 90% of maximum
298+
// Stop compacting if no entries were removed, for example if all the remaining entries are pinned with NeverRemove priority
299+
while (Compact(1 - ((0.9 * _entryCountLimit.Value) / _entries.Count)) && _entries.Count > _entryCountLimit.Value) { }
300+
}
301+
finally
302+
{
303+
_compactionSemaphore.Release();
304+
}
305+
});
303306
}
304307

305308
/// Remove at least the given percentage (0.10 for 10%) of the total entries (or estimated memory?), according to the following policy:

0 commit comments

Comments
 (0)