2017-05-08 101 views
1

如何在IdSrv4中为ClientStore实施缓存?我已经检查文档在AddClientStoreCache ,但它并不能帮助我...... 在我ConfigureServices方法我正在配置IdSrv如下:如何在IdentityServer4上实现缓存?

services.AddIdentityServer(options => 
       { 
        options.IssuerUri = "http://idp.address.jus.br/"; 
        options.Caching.ClientStoreExpiration = TimeSpan.FromHours(1); 
       }) 
       .AddSigningCredential(cert) 
       .AddClientStoreCache<ClientStore>(); 

......而在我的ClientStore执行我没有任何关于缓存...我应该检查是否有信息在缓存中FindClientByIdAsync以某种方式?或者它在发动机罩下完成了吗?

我只在IdentityServer4.Postgresql发现了一个样本,但我不能sucess复制它在我的自定义商店类...

+0

缓存是什么意思?将'clients','access_tokens'保存在数据库中? – moritzg

+0

IdrSrv有用于缓存ClientStore和ResourceStore的选项,但有任何示例... –

回答

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的好处是你可以实现你想要的接口,但是你需要它们。