You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Can you please explain why adding a null item to the cache via IAppCache.Add is disallowed ?
I'm asking because the underlying ASP.NET core memory cache allows to add null items to the cache via IMemoryCache.Set.
Is this design choice intended to avoid a situation like the following one, where the semantic of the null reference is somewhat ambiguous ?
class Program
{
static void Main(string[] args)
{
var options = new MemoryCacheOptions();
var cache = new MemoryCache(options);
cache.Set<string>("the-key", null, DateTimeOffset.UtcNow.AddDays(1));
var item = cache.Get<string>("the-key");
var otherItem = cache.Get<string>("other-key");
// both item and otherItem are null references, but item has been retrieved from the cache
}
}