如何在IdSrv4中实施ClientStore的缓存?我已经在AddClientStoreCache检查了文档 但它对我没有帮助...... 在我的 ConfigureServices 方法中,我按如下方式配置IdSrv:
services.AddIdentityServer(options =>
{
options.IssuerUri = "http://idp.address.jus.br/";
options.Caching.ClientStoreExpiration = TimeSpan.FromHours(1);
})
.AddSigningCredential(cert)
.AddClientStoreCache<ClientStore>();
...在我的 ClientStore 实现中,我没有任何关于缓存的信息...我应该以某种方式检查信息是否在 FindClientByIdAsync 中的缓存中?或者它是在引擎盖下完成的?
我仅在IdentityServer4.Postgresql找到了一个示例,但我无法在我的自定义商店类中复制它...
答案 0 :(得分:3)
如果您正在寻找CachingClientStore.cs
的示例实现,您可以查看默认实现(身份服务器执行此操作的方式)here。
public async Task<Client> FindClientByIdAsync(string clientId)
{
var client = await _cache.GetAsync(clientId,
_options.Caching.ClientStoreExpiration,
() => _inner.FindClientByIdAsync(clientId),
_logger);
return client;
}
他们正在为您提供如何实施缓存算法的选择。您可以将ClientStore缓存在内存数据库(如Redis)中。 IdentityServer4的优点是你可以随心所欲地实现接口,但是你需要它们。
答案 1 :(得分:1)
AddConfigurationStoreCache()
通过https://github.com/IdentityServer/IdentityServer4/blob/master/src/EntityFramework/host/Startup.cs#L47
答案 2 :(得分:0)
在startup.cs中,我只写:
malloc()
在DbClientStore.cs中:
NULL
答案 3 :(得分:0)
我知道这个话题有点老,但我找到了可能对某人有所帮助的解决方案。所以你只需要将以下代码添加到startup.cs
using IdentityServer4.EntityFramework.Services;
using IdentityServer4.EntityFramework.Stores;
public void ConfigureServices(IServiceCollection services)
{
services
.AddIdentityServer(options =>
{
options.Caching.ClientStoreExpiration = TimeSpan.FromMinutes(10);
options.Caching.ResourceStoreExpiration = TimeSpan.FromMinutes(10);
options.Caching.CorsExpiration = TimeSpan.FromMinutes(10);
//other options
})
.AddInMemoryCaching()
.AddClientStoreCache<ClientStore>()
.AddCorsPolicyCache<CorsPolicyService>()
.AddConfigurationStoreCache()
.AddResourceStoreCache<ResourceStore>()
//other things