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
ObjectCache
overMemoryCache
is the L in SOLID...Liskov substitution principle:
ObjectCache
is replaceable by any of its subtypes includingMemoryCache
whileMemoryCache
is not replaceable by anything forcing you into a specific implementation.