This repository was archived by the owner on Dec 14, 2018. It is now read-only.
Add to MemoryCacheOptions the CustomCompactOnMemoryPressureDelegate. #252
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add to MemoryCacheOptions the CustomCompactOnMemoryPressureDelegate.
The reason of adding the custom compact delegate:
I have tried the feature MemoryCacheOptions.CompactOnMemoryPressure = true and found that it is a good concept to trigger of revising the memory cache size when the GC collects generation 2 .
However, the compact implementation is to reduce the cache every time by 10%, it is a weird solution. By the short time it will remove everything from the cache. In the real working .net core rest web service, the cached elements have disappeared before it will be reused. So, I don't have a cache.
I propose to introduce in the MemoryCacheOptions the CustomCompactOnMemoryPressureDelegate as
public Action<MemoryCache> CustomCompactOnMemoryPressureDelegate { get; set; }
a. If you don't set this delegate the old Compact(0.10) will be invoked.
b. If setup you setup the delegate, it will be invoked instead.
For example when the Memory Cache is reached the dedicated number 110000 only in this case the compact method will be called.
Example of the custom delegate: