.Net Core MemoryCache PostEvictionCallback not working properly

To add onto the accept answer and comments, you can force the cache to expire and evict automatically by using a expiring cancellation token. int expirationMinutes = 60; var expirationTime = DateTime.Now.Add(expirationMinutes); var expirationToken = new CancellationChangeToken( new CancellationTokenSource(TimeSpan.FromMinutes(expirationMinutes + .01)).Token); var cacheEntryOptions = new MemoryCacheEntryOptions() // Pin to cache. .SetPriority(CacheItemPriority.NeverRemove) // Set the actual … Read more

C volatile variables and Cache Memory

Firmware developer here. This is a standard problem in embedded programming, and one that trips up many (even very experienced) developers. My assumption is that you are attempting to access a hardware register, and that register value can change over time (be it interrupt status, timer, GPIO indications, etc.). The volatile keyword is only part … Read more

How can I use Dependency Injection in a .Net Core ActionFilterAttribute?

As per the documentation, you have a few options here: If your filters have dependencies that you need to access from DI, there are several supported approaches. You can apply your filter to a class or action method using one of the following: ServiceFilterAttribute TypeFilterAttribute IFilterFactory implemented on your attribute ServiceFilter or TypeFilter attributes If … Read more