Exemplo n.º 1
0
        /// <summary>
        /// Called when an entry is removed from <see cref="InnerCache"/>.
        /// </summary>
        /// <param name="sender">
        /// The object that raised the message.
        /// </param>
        /// <param name="e">
        /// Event-specific arguments.
        /// </param>
        private void InnerCache_ItemsRemoved(object sender, ItemsRemovedEventArgs <TKey> e)
        {
            Interlocked.Increment(ref MessagesSent);
            if (!RedisCacheMessageSuppressionContext.IsSet(Name))
            {
                if (IsolateTenants)
                {
                    var message = new RedisPubSubPerTenantCacheMessage <TKey>(new PerTenantCacheMessage <RedisPubSubCacheMessage <TKey> >(new RedisPubSubCacheMessage <TKey>(RedisPubSubCacheMessageAction.Remove, e.Items)));

                    PerTenantChannel.Publish(
                        message,
                        PublishOptions.FireAndForget,
                        true,
                        RedisPubSubCacheHelpers.PerTenantMergeAction
                        );
                }
                else
                {
                    Channel.Publish(
                        new RedisPubSubCacheMessage <TKey>(RedisPubSubCacheMessageAction.Remove, e.Items),
                        PublishOptions.FireAndForget,
                        true,
                        RedisPubSubCacheHelpers.MergeAction
                        );
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Remove all items from the cache.
        /// </summary>
        public void Clear()
        {
            if (!RedisCacheMessageSuppressionContext.IsSet(Name))
            {
                if (IsolateTenants)
                {
                    var message = new RedisPubSubPerTenantCacheMessage <TKey>(new PerTenantCacheMessage <RedisPubSubCacheMessage <TKey> >(new RedisPubSubCacheMessage <TKey>(RedisPubSubCacheMessageAction.Clear)));

                    PerTenantChannel.Publish(message,
                                             PublishOptions.FireAndForget,
                                             true,
                                             RedisPubSubCacheHelpers.PerTenantMergeAction
                                             );
                }
                else
                {
                    Channel.Publish(
                        new RedisPubSubCacheMessage <TKey>(RedisPubSubCacheMessageAction.Clear),
                        PublishOptions.FireAndForget,
                        true,
                        RedisPubSubCacheHelpers.MergeAction
                        );
                }
            }

            using (new RedisCacheMessageSuppressionContext(Name))
            {
                InnerCache.Clear();
            }
        }