We have two types of data we need to cache using MemoryCache.
- Security token
- Book (for eg)
We don't want to set the SizeLimit on Security token cache as this will mean each entry into the cache will need to specify the size as per .NET Core doco. This is because the security tokens are inserted by a compiled nuget type that we don't have control over.
So it makes sense to create another instance of MemoryCache to hold the Book items only so we can set the size limit and size of the item while adding a book to the cache.
Also, .NET Core documentation suggests that developers need to manage the limit of cache.
I've read conflicting posts here and here which support/reject multiple memory cache instances. Additionally, these are related to .NET and not .NET Core.
Since .NET Core's MemoryCache requires developer managed eviction of cached items and considering we'll have a lot more books than tokens in the cache, we're leaning towards having 2 instances of MemoryCache.
- Security token - without any size limits which has setters in compiled nuget packages
- Books - with size limits as all the setters are within the project code
Is there any possible issues that we may run into by having multiple instances of MemoryCache in our .NET Core web application?
We're using .NET Core 2.1 with Microsoft.Extensions.Caching.Memory v=2.1.2.0