public T GetOrCreate <T>(string key, Func <T> factory, ICacheOptions cacheOptions) { return(GetOrCreate(key, factory, new MemoryCacheEntryOptions { AbsoluteExpirationRelativeToNow = cacheOptions.AbsoluteExpirationRelativeToNow })); }
public CachedCrudRepository(ICrudStore <TEntity, TKey> store, ICacheService cacheService, ICacheOptions options) : base(store, cacheService, options) { Store = store; }
public AssetRepository(IAssetStore store, ICacheService cacheService, IUserIdAccesor userIdAccesor, ICacheOptions options) : base(store, cacheService, options) { _userIdAccesor = userIdAccesor; }
public TransactionRepository(ITransactionStore store, ICacheService cacheService, IUserIdAccesor userIdAccesor, ICacheOptions options) : base(store, cacheService, options) { _userIdAccesor = userIdAccesor; }
public GroupRepository(IGroupStore store, ICacheService cacheService, IUserIdAccesor userIdAccesor, ICacheOptions options) : base(store, cacheService, options) { _userIdAccesor = userIdAccesor; }
public CachedReadOnlyRepository(IStore <TEntity, TKey> store, ICacheService cacheService, ICacheOptions options) : base(store) { CacheService = cacheService; Options = options; }
/// <summary> /// Set the builder and size parameter for the specified cache type /// </summary> /// <param name="cacheType">The cache type</param> /// <param name="options">An <see cref="ICacheOptions"/> object that /// specifies a cache builder and size to use when constructing the /// specified cache type</param> /// <returns>The <see cref="DataSetBuilder"/></returns> internal T ConfigureCache(CacheType cacheType, ICacheOptions options) { if (_cacheConfiguration.ContainsKey(cacheType)) { _cacheConfiguration.Remove(cacheType); } _cacheConfiguration.Add(cacheType, options); return((T)this); }
internal static AsyncCircuitBreakerPolicy GetCircuitBreakerPolicy( ICacheOptions options, bool debugLoggingEnabled, ILogger logger, string onBreakMessage = " ", string onResetMessage = " ", string onHalfOpenMessage = " " ) { return(Policy .Handle <CacheException>(ex => ex.ErrorCode == ErrorCodes.Common.NO_SERVER_AVAILABLE ) .CircuitBreakerAsync( exceptionsAllowedBeforeBreaking: options.ExceptionsAllowedBeforeBreaking < 0 ? 1 : options.ExceptionsAllowedBeforeBreaking, durationOfBreak: TimeSpan.FromSeconds( options.DurationOfBreakInSeconds < 0 ? 30 : options.DurationOfBreakInSeconds), onBreak: (ex, ts) => { if (debugLoggingEnabled) { logger.LogDebug( $"{onBreakMessage}\n" + $"Reason:{ex.Message}"); } }, onReset: () => { if (debugLoggingEnabled) { logger.LogDebug(onResetMessage); } }, onHalfOpen: () => { if (debugLoggingEnabled) { logger.LogDebug(onHalfOpenMessage); } })); }
public static IIdentityServerBuilder AddNCacheCaching( this IIdentityServerBuilder builder, Action <ICacheOptions> ncacheOptionsAction = null) { var options = new ICacheOptions(); ncacheOptionsAction?.Invoke(options); var logger = builder .Services .BuildServiceProvider() .GetRequiredService <ILogger <CacheHandle> >(); builder.Services.AddSingleton <CacheHandle>( new CacheHandle(options, logger)); builder.Services.AddSingleton(typeof(ICache <>), typeof(Cache <>)); return(builder); }
public CacheHandle( ICacheOptions options, ILogger <CacheHandle> logger) { this.options = options ?? throw new ArgumentNullException(nameof(options)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); cache = Utilities.CreateCache(options); var circuitBreaker = Utilities .GetCircuitBreakerPolicy( options, logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug), logger, $"ICache<T> is open circuited.\n " + $"Duration: {options.DurationOfBreakInSeconds}", $"ICache<T> circuit breaker is reset", $"ICache<T> circuit breaker is half-open"); getFallBack = GetFallBackPolicy(circuitBreaker); setFallBack = SetFallBackPolicy(circuitBreaker); }
private static async Task <bool> CreateUpdateItem(object cacheKey, object cacheObject, string region, CacheItemPolicy cacheItemPolicy, ICacheOptions cacheOptions) { var key = MemoryUtilities.CombinedKey(cacheKey, region); var cacheItem = new CacheObject { Item = await MemoryStreamHelper.SerializeObject(cacheObject) }; bool results; lock (Sync) { results = _cache.Add(key, cacheItem, cacheItemPolicy); } return(results); }
/// <summary> /// Add an item to the cache and will need to be removed manually /// </summary> /// <param name="cacheKey">The cache key.</param> /// <param name="cacheObject">The cache object.</param> /// <param name="region">If region is supported by cache , it will seperate the lookups</param> /// <param name="options">Options that can be set for the cache</param> /// <returns>true or false</returns> public override async Task <bool> AddPermanent(object cacheKey, object cacheObject, string region, ICacheOptions options) { if (!_isEnabled) { return(true); } if (await Get(cacheKey, region) != null) { await Remove(cacheKey, region); } return(await CreateUpdateItem(cacheKey, cacheObject, region, new CacheItemPolicy(), options)); }
/// <summary> /// Add to cache. /// </summary> /// <param name="cacheKey">The cache key.</param> /// <param name="cacheObject">The cache object.</param> /// <param name="region">If region is supported by cache , it will seperate the lookups</param> /// <param name="options">Options that can be set for the cache</param> /// <returns>True if successful else false.</returns> public override async Task <bool> Add(object cacheKey, object cacheObject, string region, ICacheOptions options) { if (!_isEnabled) { return(true); } if (await Get(cacheKey, region) != null) { await Remove(cacheKey, region); } options.ExpirationInMinutes = options.ExpirationInMinutes == 15 ? _cacheExpirationTime : options.ExpirationInMinutes; var cacheItemPolicy = new CacheItemPolicy(); if (options.AllowSliddingTime) { cacheItemPolicy.SlidingExpiration = TimeSpan.FromMinutes(options.ExpirationInMinutes); } else { cacheItemPolicy.AbsoluteExpiration = DateTimeOffset.UtcNow.AddMinutes(options.ExpirationInMinutes); } return(await CreateUpdateItem(cacheKey, cacheObject, region, cacheItemPolicy, options)); }
public Task <bool> AddPermanent(object cacheKey, object cacheObject, string region, ICacheOptions options) { return(Task.FromResult(true)); }
/// <summary> /// Add an item to the cache and will need to be removed manually /// </summary> /// <param name="cacheKey">The cache key.</param> /// <param name="cacheObject">The cache object.</param> /// <param name="region">If region is supported by cache , it will seperate the lookups</param> /// <param name="options">Options that can be set for the cache</param> /// <returns>true or false</returns> public override async Task <bool> AddPermanent(object cacheKey, object cacheObject, string region, ICacheOptions options) { if (!_isEnabled) { return(true); } if (await Get(cacheKey, region) != null) { await Remove(cacheKey, region); } var expireTime = DateTime.UtcNow.AddYears(100); var item = new MongoCachModel { CacheKey = cacheKey.ToString(), Expires = expireTime, CacheObject = new CacheObject { Item = await MemoryStreamHelper.SerializeObject(cacheObject) }, CacheOptions = options }; return(await CreateUpdateItem(region, item)); }
/// <summary> /// Add an item to the cache and will need to be removed manually /// </summary> /// <param name="cacheKey">The cache key.</param> /// <param name="cacheObject">The cache object.</param> /// <param name="region">If region is supported by cache , it will seperate the lookups</param> /// <param name="options">Options that can be set for the cache</param> /// <returns>true or false</returns> public abstract Task <bool> AddPermanent(object cacheKey, object cacheObject, string region, ICacheOptions options);
public AppOnlyManager(IDistributedCache store, ICacheOptions storeOptions) { this.store = store; this.storeOptions = storeOptions; this.SiteInformation = new List <SiteInformation>(); }
/// <summary> /// Add an item to the cache and will need to be removed manually /// </summary> /// <param name="cacheKey">The cache key.</param> /// <param name="cacheObject">The cache object.</param> /// <param name="region">If region is supported by cache , it will seperate the lookups</param> /// <param name="options">Options that can be set for the cache</param> /// <returns>true or false</returns> public override async Task <bool> AddPermanent(object cacheKey, object cacheObject, string region, ICacheOptions options) { if (!_isEnabled) { return(true); } var returnValue = true; foreach (var cp in CacheProviders) { if (Array.Exists(options.SkipProvider, e => e == cp.GetType().Name)) { continue; } var wasAdded = await cp.AddPermanent(cacheKey, cacheObject, region, options); if (!wasAdded) { returnValue = false; } } return(returnValue); }
public CurrencyRepository(ICurrencyStore store, ICacheService cacheService, ICacheOptions options) : base(store, cacheService, options) { }
internal void SetCacheOptions(ICacheOptions cacheSettings) { _cacheSettings = cacheSettings; }
public async Task <T> GetOrCreateAsync <T>(string key, Func <Task <T> > factory, ICacheOptions cacheOptions) { return(await GetOrCreateAsync(key, factory, new MemoryCacheEntryOptions { AbsoluteExpirationRelativeToNow = cacheOptions.AbsoluteExpirationRelativeToNow })); }