Redis vs MemoryCache

MemoryCache is embedded in the process , hence can only be used as a plain key-value store from that process. An seperate server counterpart of MemoryCache would be memcached. Whereas redis is a data structure server which can be hosted on other servers can interacted with over the network just like memcached , but redis … Read more

Is MemoryCache.Set() thread-safe?

Yes, the MemoryCache class is thread safe: System.Runtime.Caching.MemoryCache is threadsafe. Multiple concurrent threads can read and write a MemoryCache instance. Internally thread-safety is automatically handled to ensure the cache is updated in a consistent manner. What this might be referring to is that data stored within the cache may itself not be threadsafe. For example … 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 to remove all objects (reset) from IMemoryCache in ASP.NET Core

See Cache in-memory in ASP.NET Core, specifically the section on Cache dependencies. Using a CancellationTokenSource allows multiple cache entries to be evicted as a group This code worked for me: public class CacheProvider { private static CancellationTokenSource _resetCacheToken = new CancellationTokenSource(); private readonly IMemoryCache _innerCache; /* other methods and constructor removed for brevity */ public … Read more

MemoryCache AbsoluteExpiration acting strange

I’ve figured it out. There’s an internal static readonly TimeSpan on System.Runtime.Caching.CacheExpires called _tsPerBucket that is hardcoded at 20 seconds. Apparently, this field is what’s used on the internal timers that run and check to see if cache items are expired. I’m working around this by overwriting the value using reflection and clearing the default … Read more

Is MemoryCache scope session or application wide?

From MSDN: The main differences between the Cache and MemoryCache classes are that the MemoryCache class has been changed to make it usable by .NET Framework applications that are not ASP.NET applications. For example, the MemoryCache class has no dependencies on the System.Web assembly. Another difference is that you can create multiple instances of the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)