Closed coderdnewbie closed 3 years ago
I am building a webapi and want to use LazyCache. Can the SizeLimit be set? The only way that is shown to do this is:
IAppCache cacheWithSizeLimit = new CachingService( new MemoryCacheProvider(new MemoryCache(new MemoryCacheOptions { SizeLimit = 5 })));
However, I am puzzled how to do this using the DI mechanism. How do I set the SizeLimit when asp.net is making the IAppCache instance?
I found this:
services.AddMemoryCache(options => options.SizeLimit = 1000);
Would this work for lazycache, I can’t see how to do it. Please help.
Register it in DI with a factory class or factory delegate.
https://www.stevejgordon.co.uk/asp-net-core-dependency-injection-registering-implementations-using-delegates
Thanks I will try and figure that out.
I am building a webapi and want to use LazyCache. Can the SizeLimit be set? The only way that is shown to do this is:
IAppCache cacheWithSizeLimit = new CachingService( new MemoryCacheProvider(new MemoryCache(new MemoryCacheOptions { SizeLimit = 5 })));
However, I am puzzled how to do this using the DI mechanism. How do I set the SizeLimit when asp.net is making the IAppCache instance?
I found this:
services.AddMemoryCache(options => options.SizeLimit = 1000);
Would this work for lazycache, I can’t see how to do it. Please help.