So many examples of using the memory cache in .NET (including the official docs) instantiate it with:
private readonly ObjectCache memoryCache = MemoryCache.Default;
Is there any reason to prefer this over:
private readonly MemoryCache memoryCache = MemoryCache.Default;
The reason to prefer
ObjectCacheoverMemoryCacheis the L in SOLID...Liskov substitution principle:
ObjectCacheis replaceable by any of its subtypes includingMemoryCachewhileMemoryCacheis not replaceable by anything forcing you into a specific implementation.