示例#1
0
        public DeleteCommand(string key, BitSet flagMap, object lockId, LockAccessType accessType)
        {
            base.name = "DeleteCommand";
            base.key = key;

            _deleteCommand = new Alachisoft.NCache.Common.Protobuf.DeleteCommand();
            _deleteCommand.key = key;

            flagMap.SetBit(BitSetConstants.LockedItem);
            _deleteCommand.flag = flagMap.Data;
            if (lockId != null) _deleteCommand.lockId = lockId.ToString();
            _deleteCommand.lockAccessType = (int)accessType;
            _deleteCommand.requestId = base.RequestId;
        }
示例#2
0
        /// <summary>
        /// Function that choose the appropriate function of NCache's Cache, that need to be called
        /// according to the data provided to it.</summary>
        internal virtual void InsertOperation(string key, object value, DateTime absoluteExpiration,
            TimeSpan slidingExpiration, CacheItemPriority priority,
            LockHandle lockHandle, LockAccessType accessType, CacheDataNotificationCallback cacheItemUdpatedCallback,
            CacheDataNotificationCallback cacheItemRemovedCallaback, EventDataFilter itemUpdateDataFilter, EventDataFilter itemRemovedDataFilter, ref long size, bool allowQueryTags)
        {
            if (_cacheImpl == null) throw new OperationFailedException("Cache is not initialized");

            ValidateKeyValue(key, value);
            UsageStats stats = new UsageStats();
            stats.BeginSample();
            Hashtable queryInfo = new Hashtable();
            object lockId = (lockHandle == null) ? null : lockHandle.LockId;

            if (allowQueryTags)
            {
                queryInfo["query-info"] = GetQueryInfo(value);
            }
            short removeCallbackId = -1;
            short updateCallbackId = -1;
            short dsItemUpdateCallbackId = -1;

            BitSet flagMap = new BitSet();
            try
            {
                value = SafeSerialize(value, _serializationContext, ref flagMap, ref size);

                long objectSize = 0;
                if (DebugAPIConfiguraions.LoggingEnabled)
                    objectSize = value is byte[] ? ((byte[])value).Length : 0;
                if (_perfStatsCollector != null && value != null && value is byte[])
                    _perfStatsCollector.IncrementAvgItemSize(((byte[])value).Length);

                if (cacheItemRemovedCallaback != null)
                {
                    short[] callabackIds = _eventManager.RegisterSelectiveEvent(cacheItemRemovedCallaback, EventType.ItemRemoved, itemRemovedDataFilter);
                    removeCallbackId = callabackIds[1];
                }

                if (cacheItemUdpatedCallback != null)
                {
                    short[] callabackIds = _eventManager.RegisterSelectiveEvent(cacheItemUdpatedCallback, EventType.ItemUpdated, itemUpdateDataFilter);
                    updateCallbackId = callabackIds[0];
                }

                if (lockId != null && ((string)lockId) != string.Empty)
                    flagMap.SetBit(BitSetConstants.LockedItem);
                else
                    flagMap.UnsetBit(BitSetConstants.LockedItem);

                absoluteExpiration = ToUTC(absoluteExpiration);

                _cacheImpl.Insert(key, value, absoluteExpiration, slidingExpiration, priority, removeCallbackId, updateCallbackId, queryInfo, flagMap, lockId, accessType, itemUpdateDataFilter, itemRemovedDataFilter, size);

                if (_perfStatsCollector != null)
                {
                    stats.EndSample();
                    _perfStatsCollector.IncrementMsecPerUpdSample(stats.Current);
                    _perfStatsCollector.IncrementUpdPerSecStats();
                }
            }
            catch (Exception)
            {
                if (ExceptionsEnabled) throw;
            }
        }
示例#3
0
        public static object SafeSerialize(object serializableObject, string serializationContext, ref BitSet flag)
        {
            if (serializableObject != null)
            {
                if (serializableObject is byte[])
                {
                    flag.SetBit(BitSetConstants.BinaryData);
                    return serializableObject;
                }

                serializableObject = CompactBinaryFormatter.ToByteBuffer(serializableObject, serializationContext);
            }

            return serializableObject;
        }
示例#4
0
        public override object SafeSerialize(object serializableObject, string serializationContext, ref BitSet flag, CacheImplBase cacheImpl, ref long size)
        {
            if (serializableObject != null && cacheImpl.SerializationEnabled)
            {
                System.Type type = serializableObject.GetType();

                if (typeof(byte[]).Equals(type) && flag != null)
                {
                    flag.SetBit(BitSetConstants.BinaryData);
                    size = serializableObject is byte[] ? ((byte[])serializableObject).Length : 0;
                    return serializableObject;
                }
                size = serializableObject is byte[] ? ((byte[])serializableObject).Length : 0;
                serializableObject = CompactBinaryFormatter.ToByteBuffer(serializableObject, serializationContext);
            }
            return serializableObject;
        }