public CacheOptions(string methodToInterceptKey, ITypedCacheStorage <TData> storage, ICacheKeyGenerator cachedItemKeyGenerator, string region) { if (string.IsNullOrWhiteSpace(methodToInterceptKey)) { throw new ArgumentException("Value cannot be null or whitespace.", nameof(methodToInterceptKey)); } if (string.IsNullOrWhiteSpace(region)) { throw new ArgumentException("Value cannot be null or whitespace.", nameof(region)); } MethodToInterceptKey = methodToInterceptKey; CachedItemKeyGenerator = cachedItemKeyGenerator ?? throw new ArgumentNullException(nameof(cachedItemKeyGenerator)); Region = region; Storage = storage ?? throw new ArgumentNullException(nameof(storage)); }
public void Build() { _serviceCollection.AddSingleton <ICacheOptions <TResult> >(sp => { try { var regionRegister = sp.GetRequiredService <ICacheRegionRegister>(); var policyProvider = sp.GetRequiredService <ICachePolicyProvider>(); var policy = policyProvider.GetPolicy(_policy); ITypedCacheStorage <TResult> storage = policy.BuildCacheStorage <TResult>(); regionRegister.Register(storage); return(new CacheOptions <TResult>(_configurationKey, storage, _cacheKeyGenerator, _region)); } catch (Exception e) { throw new Exception("Failed to create CACHE storage. Please investigate the exception for details.", e); } }); }