3

Microsoft.AspNetCore.Identity.UserManager を使用してユーザーを管理するアプリケーションがあります。コア2.2を使用しています。UserManager は、(私ではなく) サービスに組み込まれている依存性注入によって注入されます。このような:

public MyService(UserManager<IdentityUser> userManager)
{
   _userManager = userManager;
}

初めて ID (FindByIdAsync) でユーザーを取得しようとすると、コンソールに db への要求が表示されます。同じ ID を持つ次のリクエストでは、db へのリクエストは表示されませんが、アプリケーションは動作し、ユーザーを取得しました。

Startup.cs には、userManager の構成がありません。拡張メソッドを使用するだけです:

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());
        }

質問: UserManager でこのキャッシュ機能を構成する方法はありますか? このキャッシュが残っている期間に関する情報を入手する場所を教えてください。

4

1 に答える 1