public CachedPersistedStoreCacheHandle( PersistedStoreCachingOptions options, ILogger <CachedPersistedStoreCacheHandle> logger) { this.options = options; cache = Utilities.CreateCache(options); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); var circuitBreaker = Utilities .GetCircuitBreakerPolicy( options, logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug), logger, $"PersistedGrantStoreCache is open circuited.\n " + $"Duration: {options.DurationOfBreakInSeconds}", $"PersistedGrantStoreCache circuit breaker is reset", $"PersistedGrantStoreCache circuit breaker is half-open"); getPersistedGrantPolicy = GetFallBackPolicy <PersistedGrant>(circuitBreaker); getPersistedGrantDictionaryPolicy = GetFallBackPolicy <Dictionary <string, PersistedGrant> >(circuitBreaker); setFallBackPolicy = SetFallBackPolicy(circuitBreaker); }
AddNCachePersistedGrantStoreCache <TPersistedGrantStore>( this IIdentityServerBuilder builder, Action <PersistedStoreCachingOptions> persistedGrantStoreCacheOptionsAction = null) where TPersistedGrantStore : IPersistedGrantStore { var options = new PersistedStoreCachingOptions(); persistedGrantStoreCacheOptionsAction?.Invoke(options); var logger = builder.Services.BuildServiceProvider() .GetRequiredService <ILogger <CachedPersistedStoreCacheHandle> >(); builder.Services.AddSingleton <CachedPersistedStoreCacheHandle>( new CachedPersistedStoreCacheHandle(options, logger)); builder.Services.TryAddTransient(typeof(TPersistedGrantStore)); builder.Services.AddTransient < IPersistedGrantStore, CachingPersistedGrantStore < TPersistedGrantStore> >(); return(builder); }
internal static Expiration DetermineCachePersistedGrantStoreExpiration( PersistedGrant grant, PersistedStoreCachingOptions options) { if (options.UsePersistedGrantExpiration && grant.Expiration.HasValue) { return(new Expiration( ExpirationType.Absolute, grant.Expiration.Value - DateTime.UtcNow)); } else { ExpirationType expirationType = options.Expiration == CacheExpirationType.Absolute ? ExpirationType.Absolute : ExpirationType.Sliding; TimeSpan timeSpan = TimeSpan.FromSeconds (options.TimeSpanInSeconds); return(new Expiration(expirationType, timeSpan)); } }