Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        private void OnCacheUpdated(CacheItemNotification notification)
        {
            // callback from redis
            if (callback == null)
            {
                return;
            }

            //ignore my messages
            if (sender == notification.Sender)
            {
                return;
            }

            callback(notification);
        }
Beispiel #5
0
        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);
            }
        }
Beispiel #6
0
 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);
     }
 }
Beispiel #7
0
        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);
            }
        }
Beispiel #8
0
 public RedisValue ToRedis(CacheItemNotification notification)
 {
     return(To(notification));
 }