Reputation: 131
I have switched my application from MemoryCache to DistributedSqlServerCache. After commenting out services.AddMemoryCache(), I noticed that IMemoryCache gets still injected in my classes. I use aspnet-core 2.1.
The code that adds the cache to the services:
//services.AddMemoryCache();
services.AddDistributedSqlServerCache(o =>
{
o.ConnectionString = ConnectionString;
o.SchemaName = "dbo";
o.TableName = "tbSessionCache";
});
Proof that it still gets inejcted:
Why does this happen? I think I may not get how this works. Thanks a lot!
Upvotes: 0
Views: 1768
Reputation: 46661
MVC adds a default memory cache implementation when configuring the Razor view engine. It is consumed by the cache tag helper: https://github.com/aspnet/Mvc/blob/17d2545b557863955cb5838fa16c6318931ac659/src/Microsoft.AspNetCore.Mvc.Razor/DependencyInjection/MvcRazorMvcCoreBuilderExtensions.cs#L224.
Upvotes: 1