Open MichaCo opened 7 years ago
Hi, I'm doing this implementation and I can make a pull request if you like. Instead of the proposed API I was creating a RuntimeMemoryCacheOptions like this:
public class RuntimeMemoryCacheOptions
{
public int CacheMemoryLimitMegabytes { get; set; } = 0;
public int PhysicalMemoryLimitPercentage { get; set; } = 0;
public TimeSpan PollingInterval { get; set; } = TimeSpan.FromMinutes(2);
}
and the API would be like this:
.WithSystemRuntimeCacheHandle("CustomCache", new RuntimeMemoryCacheOptions(){ PollingInterval = TimeSpan.FromMinutes(5), PhysicalMemoryLimitPercentage = 0, CacheMemoryLimitMegabytes = 10});
The RuntimeMemoryCacheOptions class has a method AsNameValueCollection to convert the configuration to a NameValueCollection required for creating the MemoryCache.
@nflash sounds good, I think you'd have to add 2 additional extension methods for adding the handle, basically the same ones which already exist but with the addition of the new options. Make sure the options are totally optional and the old way via web/app config will still work.
But that's only one way to configure it:
Yup, feel free to send a PR :)
The only way to configure the memory pressure or limits of the System.Runtime.Caching.MemoryCache based handle is via app/web.config. The implementation already supports named caches, there could be at least overloads for the builder extension methods to define the following three properties...
API proposal: