public void Publish(string cacheName, string key, CacheItemActionTypes action) { var message = new CacheItemNotification(sender, cacheName, key, action); var messageToSend = convert.ToRedis(message); GetSubClient(cacheName, null).Subscriber.Publish(cacheName, messageToSend, CommandFlags.None); }
public void Publish(string key, CacheItemActionTypes action) { var message = new CacheItemNotification(sender, cacheName, key, action); var messageToSend = convert.ToRedis(message); // publish via redis client.Subscriber.Publish(cacheName, messageToSend, CommandFlags.FireAndForget); }
public async Task PublishAsync(string cacheName, string key, CacheItemActionTypes action) { var message = new CacheItemNotification(sender, cacheName, key, action); var messageToSend = convert.ToRedis(message); await GetSubClient(cacheName, null, null).Subscriber .PublishAsync(cacheName, messageToSend, CommandFlags.None) .ConfigureAwait(false); }
private void OnCacheUpdated(CacheItemNotification notification) { // callback from redis if (callback == null) { return; } //ignore my messages if (sender == notification.Sender) { return; } callback(notification); }
private void OnCacheUpdated(CacheItemNotification notification) { if (notification.CacheName == null) { return; } // Ignore own messages - prevent loops if (sender == notification.Sender) { return; } if (this.cacheCallbacks.TryGetValue( notification.CacheName, out Func <CacheItemNotification, bool> callback)) { // CacheSynchronizer callback callback(notification); } }
public bool TryPublish(string cacheName, string key, CacheItemActionTypes action) { try { var message = new CacheItemNotification(sender, cacheName, key, action); var messageToSend = convert.ToRedis(message); var redisClient = GetSubClient(cacheName, null, null); if (redisClient.IsConnected) { redisClient.Subscriber.Publish(cacheName, messageToSend, CommandFlags.None); return(true); } return(false); } catch (Exception ex) { log.Warn(ex, $"Failed to publish {action} for {cacheName}.{key}"); return(false); } }
private void OnCacheUpdated(CacheItemNotification notification) { if (notification.CacheName == null) { return; } // Ignore own messages - prevent loops if (sender == notification.Sender) { return; } if (this.cacheCallbacks.TryGetValue( notification.CacheName, out Func <CacheItemNotification, bool> callback)) { log.Debug($"Received {nameof(CacheItemNotification)} for cache={notification.CacheName}, key={notification.Key}"); // CacheSynchronizer callback callback(notification); } }
public RedisValue ToRedis(CacheItemNotification notification) { return(To(notification)); }