I have an application that uses Microsoft.AspNetCore.Identity.UserManager to manage users. I use core 2.2. UserManager is injected by built-in dependency injection in my services (not by me). like this:
public MyService(UserManager<IdentityUser> userManager)
{
_userManager = userManager;
}
When I try to get a user by Id (FindByIdAsync) for the first time I see a request to db in a console. Next requests with the same Id I do not see any request to db, but the application works and got user.
In Startup.cs I do not have a configuration for userManager. I just use the extension method:
public void ConfigureServices(IServiceCollection services)
{
services
.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("MyConnectionString"));
services
.AddIdentity<IdentityUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
services.AddMvc();
var configService = new ConfigurationService(Configuration);
services
.AddIdentityServer()
.AddDeveloperSigningCredential()
.AddInMemoryApiResources(configService.GetApiResources())
.AddInMemoryClients(configService.GetClients())
.AddTestUsers(configService.GetUsers());
}
Question: Maybe there is a way how to configure this caching feature in UserManager? Point me out where to get information about how long this cache leaves.