internal CachingStoreWrapper(IFeatureStoreCore core, FeatureStoreCacheConfig caching) { this._core = core; this._caching = caching; if (caching.IsEnabled) { var itemCacheBuilder = Caches.KeyValue <CacheKey, IVersionedData>() .WithLoader(GetInternalForCache) .WithMaximumEntries(caching.MaximumEntries); var allCacheBuilder = Caches.KeyValue <IVersionedDataKind, ImmutableDictionary <string, IVersionedData> >() .WithLoader(GetAllForCache); var initCacheBuilder = Caches.SingleValue <bool>() .WithLoader(_core.InitializedInternal); if (!caching.IsInfiniteTtl) { itemCacheBuilder.WithExpiration(caching.Ttl); allCacheBuilder.WithExpiration(caching.Ttl); initCacheBuilder.WithExpiration(caching.Ttl); } _itemCache = itemCacheBuilder.Build(); _allCache = allCacheBuilder.Build(); _initCache = initCacheBuilder.Build(); } else { _itemCache = null; _allCache = null; _initCache = null; } }
internal PersistentStoreWrapper( IPersistentDataStore core, DataStoreCacheConfig caching, IDataStoreUpdates dataStoreUpdates, TaskExecutor taskExecutor, Logger log ) { this._core = core; this._caching = caching; this._dataStoreUpdates = dataStoreUpdates; this._log = log; _cacheIndefinitely = caching.IsEnabled && caching.IsInfiniteTtl; if (caching.IsEnabled) { var itemCacheBuilder = Caches.KeyValue <CacheKey, ItemDescriptor?>() .WithLoader(GetInternalForCache) .WithMaximumEntries(caching.MaximumEntries); var allCacheBuilder = Caches.KeyValue <DataKind, ImmutableDictionary <string, ItemDescriptor> >() .WithLoader(GetAllAndDeserialize); var initCacheBuilder = Caches.SingleValue <bool>() .WithLoader(_core.Initialized); if (!caching.IsInfiniteTtl) { itemCacheBuilder.WithExpiration(caching.Ttl); allCacheBuilder.WithExpiration(caching.Ttl); initCacheBuilder.WithExpiration(caching.Ttl); } _itemCache = itemCacheBuilder.Build(); _allCache = allCacheBuilder.Build(); _initCache = initCacheBuilder.Build(); } else { _itemCache = null; _allCache = null; _initCache = null; } _statusManager = new PersistentDataStoreStatusManager( !_cacheIndefinitely, true, this.PollAvailabilityAfterOutage, dataStoreUpdates.UpdateStatus, taskExecutor, log ); }