public AuthenticationApiClientCachingDecorator(IAuthenticationApiClient inner)
        {
            _inner = inner;
            _accessTokenResponseCachePolicy = AsyncRequestCollapserPolicy.Create()
                                              .WrapAsync(
                Policy.CacheAsync(
                    _memoryCacheProvider.AsyncFor <AccessTokenResponse>(),
                    new ResultTtl <AccessTokenResponse>(r => new Ttl(_expiresIn(r), false)))
                );

            _userInfoCachePolicy = AsyncRequestCollapserPolicy.Create()
                                   .WrapAsync(
                Policy.CacheAsync(
                    _memoryCacheProvider.AsyncFor <UserInfo>(),
                    new ContextualTtl())
                );
        }
Пример #2
0
 protected override IsPolicy GetPolicy(bool useCollapser, IKeyStrategy overrideKeyStrategy = null, ISyncLockProvider lockProvider = null)
 {
     return(useCollapser ?
            AsyncRequestCollapserPolicy <ResultClass> .Create(overrideKeyStrategy ?? RequestCollapserPolicy.DefaultKeyStrategy, new AsyncWrapperLockProvider(lockProvider ?? RequestCollapserPolicy.GetDefaultLockProvider()))
         : (IAsyncPolicy <ResultClass>)Policy.NoOpAsync <ResultClass>());
 }