void NotifyUpdated(IUpdateContextCodeFeature update, ICachedCodeFeatureState updatedFeatureState) { var updatedEvent = new ContextCodeFeatureStateCacheUpdated(update.ContextId, update.ContextKey, updatedFeatureState.Id, updatedFeatureState.Enabled, update.CommandId); _cacheUpdated.ForEach(x => x.OnNext(updatedEvent)); }
public void UpdateCache(IUpdateCodeFeature update) { CodeFeatureId codeFeatureId = update.CodeFeatureId; ICachedCodeFeatureState existingFeatureState; if (_cache.TryGetState(codeFeatureId, out existingFeatureState)) { if (existingFeatureState.Enabled == update.Enabled) { return; } var updatedFeatureState = new CachedCodeFeatureState(codeFeatureId, update.Enabled); DateTime startTime = DateTime.UtcNow; bool updated = _cache.TryUpdate(codeFeatureId, updatedFeatureState, existingFeatureState); DateTime endTime = DateTime.UtcNow; if (updated) { var updatedEvent = new CodeFeatureStateCacheUpdated(startTime, endTime - startTime, updatedFeatureState.Id, updatedFeatureState.Enabled, update.CommandId); _cacheUpdated.ForEach(x => x.OnNext(updatedEvent)); } } else { var featureState = new CachedCodeFeatureState(codeFeatureId, update.Enabled); DateTime startTime = DateTime.UtcNow; bool updated = _cache.TryAdd(codeFeatureId, featureState); DateTime endTime = DateTime.UtcNow; if (updated) { var updatedEvent = new CodeFeatureStateCacheUpdated(startTime, endTime - startTime, featureState.Id, featureState.Enabled, update.CommandId); _cacheUpdated.ForEach(x => x.OnNext(updatedEvent)); } } }
public async Task ReloadCache() { DateTime startTime = DateTime.UtcNow; ICodeFeatureStateCacheInstance cache = await LoadCache(); DateTime endTime = DateTime.UtcNow; Interlocked.Exchange(ref _cache, cache); var loaded = new CodeFeatureStateCacheLoaded(startTime, endTime - startTime, cache.Count); _cacheLoaded.ForEach(x => x.OnNext(loaded)); }