Exemple #1
0
        private CacheEventArg CreateCacheEventArgument(EventDataFilter dataFilter, string key, string cacheName, EventType eventType, EventCacheItem item, EventCacheItem oldItem, CacheItemRemovedReason removedReason)
        {
            EventCacheItem cloneItem    = null;
            EventCacheItem cloneOldItem = null;

            if (dataFilter != EventDataFilter.None && item != null)
            {
                cloneItem = item.Clone() as EventCacheItem;

                if (dataFilter == EventDataFilter.Metadata)
                {
                    cloneItem.Value = null;
                }
            }

            if (dataFilter != EventDataFilter.None && oldItem != null)
            {
                cloneOldItem = oldItem.Clone() as EventCacheItem;

                if (dataFilter == EventDataFilter.Metadata)
                {
                    cloneOldItem.Value = null;
                }
            }

            CacheEventArg eventArg = new CacheEventArg(key, cacheName, eventType, cloneItem, null, removedReason);

            if (eventType == EventType.ItemUpdated)
            {
                eventArg.OldItem = cloneOldItem;
            }

            return(eventArg);
        }
Exemple #2
0
        /// <summary>
        /// TheadSafe and no locks internally
        /// </summary>
        /// <param name="key"></param>
        /// <param name="eventType">Should contain one type i.e. should not be used as a flag.
        /// Every EventType should be executed from another thread</param>
        /// <param name="item"></param>
        /// <param name="oldItem"></param>
        /// <param name="reason"></param>
        /// <param name="_notifyAsync"></param>
        /// <param name="eventhandle"></param>
        internal void RaiseSelectiveCacheNotification(string key, EventType eventType, EventCacheItem item,
                                                      EventCacheItem oldItem, CacheItemRemovedReason reason, bool _notifyAsync, EventHandle eventhandle,
                                                      EventDataFilter dataFilter)
        {
            try
            {
                ResourcePool poolID = null;

                CacheEventArg arg = null;

                if ((eventType & EventType.ItemUpdated) != 0)
                {
                    poolID = _selectiveUpdateEventIDPool;
                }
                else if ((eventType & EventType.ItemRemoved) != 0)
                {
                    poolID = _selectiveRemoveEventIDPool;
                }

                arg = CreateCacheEventArgument(dataFilter, key, _cacheName, eventType, item, oldItem, reason);

                if (poolID == null)
                {
                    return;
                }

                CacheDataNotificationCallback callback =
                    poolID.GetResource((short)eventhandle.Handle) as CacheDataNotificationCallback;

                if (callback == null)
                {
                    return;
                }

                if (_notifyAsync)
                {
                    System.Threading.ThreadPool.QueueUserWorkItem(waitC,
                                                                  new object[] { callback, key, arg });
                }
                else
                {
                    callback.Invoke(key, arg);
                }
            }
            catch (Exception ex)
            {
                if (_logger != null && _logger.IsErrorEnabled)
                {
                    _logger.CriticalInfo(ex.ToString());
                }
            }
        }
Exemple #3
0
 private static void KeyNotificationMethod(string key, CacheEventArg cacheEventArgs)
 {
     switch (cacheEventArgs.EventType)
     {
         case EventType.ItemAdded:
             Console.WriteLine("Key: " + key + " is added to the cache");
             break;
         case EventType.ItemRemoved:
             Console.WriteLine("Key: " + key + " is removed from the cache");
             break;
         case EventType.ItemUpdated:
             Console.WriteLine("Key: " + key + " is updated in the cache");
             break;
     }
 }
        public void OnCacheDataNotification(string key, CacheEventArg eventArgs)
        {
            switch (eventArgs.EventType)
            {
            case EventType.ItemAdded:
                _parentCache.EventListener.OnItemAdded(key, false);
                break;

            case EventType.ItemUpdated:
                _parentCache.EventListener.OnItemUpdated(key, false);
                break;

            case EventType.ItemRemoved:
                _parentCache.EventListener.OnItemRemoved(key, eventArgs.Item.Value,
                                                         eventArgs.CacheItemRemovedReason, false);
                break;
            }
        }
Exemple #5
0
        private CacheEventArg CreateCacheEventArgument(EventDataFilter dataFilter, string key,string cacheName,EventType eventType,EventCacheItem item,EventCacheItem oldItem,CacheItemRemovedReason removedReason)
        {
            EventCacheItem cloneItem = null;
            EventCacheItem cloneOldItem = null;

            if (dataFilter != EventDataFilter.None && item != null)
            {
                cloneItem = item.Clone() as EventCacheItem;

                if (dataFilter == EventDataFilter.Metadata)
                    cloneItem.Value = null;
            }

            if (dataFilter != EventDataFilter.None && oldItem != null)
            {
                cloneOldItem = oldItem.Clone() as EventCacheItem;

                if (dataFilter == EventDataFilter.Metadata)
                    cloneOldItem.Value = null;
            }

            CacheEventArg eventArg = new CacheEventArg(key, cacheName, eventType, cloneItem, null, removedReason);
            if (eventType == EventType.ItemUpdated) eventArg.OldItem = cloneOldItem;

            return eventArg;
        }
Exemple #6
0
 public static void CacheDataModified(string @string, CacheEventArg cacheEventArgs)
 {
     Console.WriteLine("Cache data modification notification for the the item of the key : {0}", @string); //To change body of generated methods, choose Tools | Templates.
 }