/// <summary> /// Force updating the cache params. /// </summary> internal void ForceUpdateCacheParams(ISupplier <MemoryCacheParams> cacheParamsSupplier) { lock (_cacheGate) { long currentTime = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; _lastCacheParamsCheck = currentTime; _memoryCacheParams = cacheParamsSupplier.Get(); } }
/// <summary> /// Updates the cache params (constraints) if enough time has passed /// since the last update. /// </summary> private void MaybeUpdateCacheParams() { lock (_cacheGate) { long currentTime = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; if (_lastCacheParamsCheck + PARAMS_INTERCHECK_INTERVAL_MS > currentTime) { return; } _lastCacheParamsCheck = currentTime; _memoryCacheParams = _memoryCacheParamsSupplier.Get(); } }
/// <summary> /// Instantiates the <see cref="CountingMemoryCache{K, V}"/>. /// </summary> public CountingMemoryCache( IValueDescriptor <V> valueDescriptor, ICacheTrimStrategy cacheTrimStrategy, ISupplier <MemoryCacheParams> memoryCacheParamsSupplier, PlatformBitmapFactory platformBitmapFactory, bool isExternalCreatedBitmapLogEnabled) { _valueDescriptor = valueDescriptor; _exclusiveEntries = new CountingLruMap <K, Entry>(WrapValueDescriptor(valueDescriptor)); _cachedEntries = new CountingLruMap <K, Entry>(WrapValueDescriptor(valueDescriptor)); _cacheTrimStrategy = cacheTrimStrategy; _memoryCacheParamsSupplier = memoryCacheParamsSupplier; _memoryCacheParams = _memoryCacheParamsSupplier.Get(); _lastCacheParamsCheck = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; if (isExternalCreatedBitmapLogEnabled) { platformBitmapFactory.SetCreationListener( new BitmapCreationObserverImpl((b, o) => _otherEntries.Add(b, o))); } }