AddMemoryCache() lifecycle
Hi, I have an AzureWebJob which spins up new instances of a transient class to do work on a schedule. I'm looking at adding some caching, but I want the cache scoped to the instance of the transient class (a new cache each time). As far as I can tell, the AddMemoryCache() invokes:
services.TryAdd(ServiceDescriptor.Singleton<IMemoryCache, MemoryCache>());
and thereofre it's going to give me the same MemoryCache instance forever. Given this, should I bother using DI at all? Should I just create a new MemoryCache instance in my class that needs the cache? Should I manually add the MemoryCache as a transient instead of singleton?0 Replies