internal short RegisterSelectiveCallback(CacheItemUpdatedCallback updateCallback, CallbackType callbackType) { 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, EventTypeInternal.ItemUpdated, EventDataFilter.None, callbackType); return(callbackIds[0]); } }
internal short UnRegisterSelectiveCallback(CacheItemUpdatedCallback updateCallback) { if (updateCallback == null) { return(-1); } lock (SyncLockSelective) { SelectiveUpdateCallbackWrapper callbackWrapper = (SelectiveUpdateCallbackWrapper)_oldSelectiveCallbackPool.GetResource(updateCallback); //a callback more then one time or against wrong items. if (callbackWrapper != null) { short[] callbackIds = RegisterSelectiveEvent(callbackWrapper.MappingCallback, EventTypeInternal.ItemUpdated, EventDataFilter.None); return(callbackIds[0]); } return(-1); } }