Beispiel #1
0
 public void OnCacheDataNotification(string key, CacheEventArg arg)
 {
     if (_callback != null)
     {
         _callback(key);
     }
 }
Beispiel #2
0
 public void OnCacheDataNotification(string key, CacheEventArg arg)
 {
     if (_callback != null)
     {
         _callback(key, arg.Item.GetValue <object>(), arg.CacheItemRemovedReason);
     }
 }
Beispiel #3
0
        private CacheEventArg CreateCacheEventArgument(EventDataFilter dataFilter, string key, string cacheName, EventType eventType, EventCacheItem item, EventCacheItem oldItem, CacheItemRemovedReason removedReason)
        {
            EventCacheItem cloneItem    = null;
            EventCacheItem cloneOldItem = null;

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

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

            return(eventArg);
        }
Beispiel #4
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;
                var           bitSet = new BitSet();

                if (_cache.SerializationFormat == Common.Enum.SerializationFormat.Json)
                {
                    bitSet.SetBit(BitSetConstants.JsonData);
                }

                if (item != null)
                {
                    item.SetValue(_cache.SafeDeserialize <object>(item.GetValue <object>(), _cache.SerializationContext, bitSet, UserObjectType.CacheItem));
                }
                if (oldItem != null)
                {
                    oldItem.SetValue(_cache.SafeDeserialize <object>(oldItem.GetValue <object>(), _cache.SerializationContext, bitSet, UserObjectType.CacheItem));
                }
                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) //Can occur if Unregistered concurrently
                {
                    return;
                }

                if (_notifyAsync)
                {
                    System.Threading.ThreadPool.QueueUserWorkItem(waitC, new object[] { callback, key, arg }); //Faster and better
                }
                else
                {
                    callback.Invoke(key, arg);
                }
            }
            catch (Exception ex)
            {
                if (_logger != null && _logger.IsErrorEnabled)
                {
                    _logger.CriticalInfo(ex.ToString());
                }
            }
        }