private void PropagateEvent(string keyName, PropagationAction action, IRawCache originBackend, IEnumerable <IRawCache> targetBackends) { switch (action) { case PropagationAction.Delete: { var deleteTasks = targetBackends.Select(backend => backend.DeleteAsync(keyName)); Task.WhenAll(deleteTasks).Wait(); break; } case PropagationAction.UpdateTimeToLive: { var timeToLive = originBackend.GetTimeToLiveAsync(keyName).Result; var updateTimeToLiveTasks = targetBackends.Select(backend => backend.ExpireInAsync(keyName, timeToLive)); Task.WhenAll(updateTimeToLiveTasks).Wait(); break; } } }
private async Task SubscribeAsync(IEnumerable <IRawCache> cacheBackends) { var parentBackends = new List <IRawCache>(); foreach (var backend in cacheBackends) { var subscribableBackend = backend as ISubscribable; if (subscribableBackend != null) { IRawCache currentBackend = backend; var targetBackends = new List <IRawCache>(parentBackends); await subscribableBackend.SubscribeToDeleteAsync( (eventType, keyName) => PropagateEvent(keyName, PropagationAction.Delete, currentBackend, targetBackends)).ConfigureAwait(false); await subscribableBackend.SubscribeToUpdateTimeToLiveAsync( (eventType, keyName) => PropagateEvent(keyName, PropagationAction.UpdateTimeToLive, currentBackend, targetBackends)).ConfigureAwait(false); } parentBackends.Add(backend); } }
public RawCacheTests(string backendName) { switch (backendName) { case "redis": this._cacheBackend = ResourceFactory.GetRedisCache(); break; case "inProcess": this._cacheBackend = ResourceFactory.GetInProcessCache(); break; } }