Ejemplo n.º 1
0
        internal short RegisterSelectiveCallback(CacheItemUpdatedCallback updateCallback)
        {
            if (updateCallback == null)
            {
                return(-1);
            }

            SelectiveUpdateCallbackWrapper callbackWrapper = null;

            lock (SyncLockSelective)
            {
                // callback is not already registered with the same method, so add
                if (_oldSelectiveCallbackPool.GetResource(updateCallback) == null)
                {
                    callbackWrapper = new SelectiveUpdateCallbackWrapper(updateCallback);
                    _oldSelectiveCallbackPool.AddResource(updateCallback, callbackWrapper);
                    _oldSelectiveMappingCallbackPool.AddResource(callbackWrapper, updateCallback);
                }
                // already present against the same method, so no need to add again.
                else
                {
                    callbackWrapper =
                        (SelectiveUpdateCallbackWrapper)_oldSelectiveCallbackPool.GetResource(updateCallback);
                    _oldSelectiveCallbackPool.AddResource(updateCallback, callbackWrapper); //to increment the refcount
                }

                short[] callbackIds = RegisterSelectiveEvent(callbackWrapper.MappingCallback, EventType.ItemUpdated,
                                                             EventDataFilter.None);
                return(callbackIds[0]);
            }
        }
Ejemplo n.º 2
0
        internal short UnRegisterSelectiveCallback(CacheItemUpdatedCallback updateCallback)
        {
            if (updateCallback == null)
            {
                return(-1);
            }
            lock (SyncLockSelective)
            {
                SelectiveUpdateCallbackWrapper callbackWrapper =
                    (SelectiveUpdateCallbackWrapper)_oldSelectiveCallbackPool.GetResource(updateCallback);
                // For selective callback, we dont remove the callback from resource pool as it can create chaos if user try to unregister
                //a callback more then one time or against wrong items.
                if (callbackWrapper != null)
                {
                    short[] callbackIds = RegisterSelectiveEvent(callbackWrapper.MappingCallback, EventType.ItemUpdated,
                                                                 EventDataFilter.None);
                    return(callbackIds[0]);
                }

                return(-1);
            }
        }