Пример #1
0
        /// <summary>
        /// Removes the objects for the given keys from the cache.
        /// The keys are specified as parameter.
        /// </summary>
        /// <param name="keys">array of keys to be removed</param>
        /// <param name="flagMap"></param>
        /// <param name="cbEntry"></param>
        /// <param name="operationContext"></param>
        /// <returns>keys that failed to be removed</returns>
        public IDictionary Remove(object[] keys, BitSet flagMap, CallbackEntry cbEntry, OperationContext operationContext)
        {
            if (keys == null) throw new ArgumentNullException("keys");

            // Cache has possibly expired so do default.
            if (!IsRunning) return null; 

            try
            {
                HPTimeStats removeTime = new HPTimeStats();
                removeTime.BeginSample();

                IDictionary removed = CascadedRemove(keys, ItemRemoveReason.Removed, true, operationContext);
                removeTime.EndSample();

                CompressedValueEntry val = null;
                if (removed != null)
                {
                    object[] keysCollection = new object[removed.Count];
                    removed.Keys.CopyTo(keysCollection, 0);
                    IEnumerator ie = keysCollection.GetEnumerator();
                    while (ie.MoveNext())
                    {
                        CacheEntry entry = removed[ie.Current] as CacheEntry;
                        if (entry != null)
                        {
                            val = new CompressedValueEntry();
                            val.Value = entry.Value;
                            if (val.Value is CallbackEntry)
                                val.Value = ((CallbackEntry)val.Value).Value;
                            val.Flag = entry.Flag;
                            removed[ie.Current] = val;
                        }
                    }
                }
                return removed;
            }
            catch (Exception inner)
            {
                _context.NCacheLog.Error("Cache.Remove()", inner.ToString());
                throw new OperationFailedException("Remove operation failed. Error : " + inner.Message, inner);
            }
            return null;
        }
Пример #2
0
        /// <summary>
        /// Removes the objects for the given keys from the cache.
        /// The keys are specified as parameter.
        /// </summary>
        /// <param name="keys">array of keys to be removed</param>
        public void Delete(object[] keys, BitSet flagMap, CallbackEntry cbEntry, OperationContext operationContext)
        {
            if (keys == null) throw new ArgumentNullException("keys");

            // Cache has possibly expired so do default.
            if (!IsRunning) return; 

           

            try
            {
                HPTimeStats removeTime = new HPTimeStats();
                removeTime.BeginSample();
                IDictionary removed = CascadedRemove(keys, ItemRemoveReason.Removed, true, operationContext);
                removeTime.EndSample();
            }
            catch (Exception inner)
            {
                _context.NCacheLog.Error("Cache.Delete()", inner.ToString());
                throw new OperationFailedException("Delete operation failed. Error : " + inner.Message, inner);
            }
        }
Пример #3
0
        public void Delete(string key, BitSet flag, CallbackEntry cbEntry, object lockId, LockAccessType accessType, OperationContext operationContext)
        {
            if (key == null) throw new ArgumentNullException("key");
            if (!key.GetType().IsSerializable)
                throw new ArgumentException("key is not serializable");

            // Cache has possibly expired so do default.
            if (!IsRunning) return;

            try
            {
                HPTimeStats removeTime = new HPTimeStats();
                removeTime.BeginSample();

                _context.PerfStatsColl.MsecPerDelBeginSample();

                object packedKey = key;

                CacheEntry e = CascadedRemove(key, packedKey, ItemRemoveReason.Removed, true, lockId,accessType, operationContext);

                _context.PerfStatsColl.MsecPerDelEndSample();
                _context.PerfStatsColl.IncrementDelPerSecStats();
                removeTime.EndSample();
            }
            catch (OperationFailedException ex)
            {
                if (ex.IsTracable) _context.NCacheLog.Error("Cache.Delete()", ex.ToString());
                throw ex;
            }
            catch (Exception inner)
            {
                _context.NCacheLog.Error("Cache.Delete()", inner.ToString());
                throw new OperationFailedException("Delete operation failed. Error : " + inner.Message, inner);
            }
        }
Пример #4
0
        /// <summary>
        /// Overload of Insert operation for bulk inserts. Uses EvictionHint and ExpirationHint arrays.
        /// </summary>
        public IDictionary Insert(object[] keys, object[] values, CallbackEntry[] callbackEnteries,
                                           ExpirationHint[] expirations, EvictionHint[] evictions,
                                           Hashtable[] queryInfos, BitSet[] flags,OperationContext operationContext)
        {
            if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("Cache.InsertBlk", "");

            if (keys == null) throw new ArgumentNullException("keys");
            if (values == null) throw new ArgumentNullException("items");
            if (keys.Length != values.Length) throw new ArgumentException("keys count is not equals to values count");
           

            CacheEntry[] ce = new CacheEntry[values.Length];
            long[] sizes = null;
            object dataSize = operationContext.GetValueByField(OperationContextFieldName.ValueDataSize);
            if (dataSize != null)
            {
                sizes = (long[])dataSize;
            }
            for (int i = 0; i < values.Length; i++)
            {

                if (keys[i] == null) throw new ArgumentNullException("key");
                if (values[i] == null) throw new ArgumentNullException("value");

                if (!keys[i].GetType().IsSerializable)
                    throw new ArgumentException("key is not serializable");
                if (!values[i].GetType().IsSerializable)
                    throw new ArgumentException("value is not serializable");
                if ((expirations[i] != null) && !expirations[i].GetType().IsSerializable)
                    throw new ArgumentException("expiryHint is not not serializable");
                if ((evictions[i] != null) && !evictions[i].GetType().IsSerializable)
                    throw new ArgumentException("evictionHint is not serializable");

                // Cache has possibly expired so do default.
                if (!IsRunning) return null;

                ce[i] = new CacheEntry(values[i], expirations[i], evictions[i]);



                ce[i].QueryInfo = queryInfos[i];
                ce[i].Flag.Data |= flags[i].Data;
                if(sizes != null)
                    ce[i].DataSize = sizes[i];
                if (callbackEnteries[i] != null)
                {
                    CallbackEntry cloned = callbackEnteries[i].Clone() as CallbackEntry;
                    cloned.Value = values[i];
                    cloned.Flag = ce[i].Flag;
                    ce[i].Value = cloned;
                }
            }

            /// update the counters for various statistics
            try
            {
               

                HPTimeStats insertTime = new HPTimeStats();
                insertTime.BeginSample();

                IDictionary result = Insert(keys, ce, operationContext);

                insertTime.EndSample();

                return result;
            }
            catch (Exception inner)
            {
                throw;
            }
        }
Пример #5
0
        /// <summary>
        /// Internal Insert operation. Does a write thru as well.
        /// </summary>
        private void Insert(object key, CacheEntry e, object lockId, LockAccessType accessType, OperationContext operationContext)
        {
           
            HPTimeStats insertTime = new HPTimeStats();
            insertTime.BeginSample();

            object value = e.Value;
            try
            {
                CacheInsResultWithEntry retVal = CascadedInsert(key, e, true, lockId, accessType, operationContext);
                insertTime.EndSample();

                switch (retVal.Result)
                {
                    case CacheInsResult.Failure:
                        break;

                    case CacheInsResult.NeedsEviction:
                    case CacheInsResult.NeedsEvictionNotRemove:
                       throw new OperationFailedException("The cache is full and not enough items could be evicted.", false);

                    case CacheInsResult.SuccessOverwrite:
                        _context.PerfStatsColl.IncrementUpdPerSecStats();
                        break;
                    case CacheInsResult.Success:
                        _context.PerfStatsColl.IncrementAddPerSecStats();
                        break;
                    case CacheInsResult.ItemLocked:
                        throw new LockingException("Item is locked.");
                }
            }
            catch (OperationFailedException inner)
            {
                if (inner.IsTracable) _context.NCacheLog.Error("Cache.Insert():", inner.ToString());
                throw;
            }
            catch (Exception inner)
            {
                _context.NCacheLog.Error("Cache.Insert():", inner.ToString());
                _context.NCacheLog.CriticalInfo("Cache.Insert():", inner.ToString());

                throw new OperationFailedException("Insert operation failed. Error : " + inner.Message, inner);
            }
        }
Пример #6
0
        /// <summary>
        /// Overload of Add operation. uses additional paramer of Flag for checking if compressed or not
        /// </summary>
        public void Add(object key, object value,
                        ExpirationHint expiryHint, EvictionHint evictionHint,
                        Hashtable queryInfo, BitSet flag, 
                       OperationContext operationContext)
        {
            if (key == null) throw new ArgumentNullException("key");
            if (value == null) throw new ArgumentNullException("value");

            if (!key.GetType().IsSerializable)
                throw new ArgumentException("key is not serializable");
            if (!value.GetType().IsSerializable)
                throw new ArgumentException("value is not serializable");
            if ((expiryHint != null) && !expiryHint.GetType().IsSerializable)
                throw new ArgumentException("expiryHint is not serializable");
            if ((evictionHint != null) && !evictionHint.GetType().IsSerializable)
                throw new ArgumentException("evictionHint is not serializable");

            // Cache has possibly expired so do default.
            if (!IsRunning) return; 
           
            CacheEntry e = new CacheEntry(value, expiryHint, evictionHint);
            ////Object size for inproc
            object dataSize = operationContext.GetValueByField(OperationContextFieldName.ValueDataSize);
            if (dataSize != null)
                e.DataSize = Convert.ToInt64(dataSize);
           
            e.QueryInfo = queryInfo;
            e.Flag.Data |= flag.Data;        
            try
            {
                HPTimeStats addTime = new HPTimeStats();
                _context.PerfStatsColl.MsecPerAddBeginSample();
                
                addTime.BeginSample();
                Add(key, e, operationContext);
                addTime.EndSample();
                _context.PerfStatsColl.MsecPerAddEndSample();
            }
            catch (Exception inner)
            {
                throw;
            }
        }
Пример #7
0
        public CompressedValueEntry Get(object key, BitSet flagMap,ref object lockId, ref DateTime lockDate, TimeSpan lockTimeout, LockAccessType accessType, OperationContext operationContext)
        {
            if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("Cache.GetGrp", "");
            // Cache has possibly expired so do default.
            if (!IsRunning) return null; 

            CompressedValueEntry result = new CompressedValueEntry();
            CacheEntry e = null;
            try
            {
                _context.PerfStatsColl.MsecPerGetBeginSample();
                _context.PerfStatsColl.IncrementGetPerSecStats();
                _context.PerfStatsColl.IncrementHitsRatioPerSecBaseStats();
                HPTimeStats getTime = new HPTimeStats();
                getTime.BeginSample();

                LockExpiration lockExpiration = null;
                if (accessType == LockAccessType.ACQUIRE)
                {
                    lockId = GetLockId(key);
                    lockDate = DateTime.UtcNow;

                    if (!TimeSpan.Equals(lockTimeout, TimeSpan.Zero))
                    {
                        lockExpiration = new LockExpiration(lockTimeout);
                    }
                }

                object generatedLockId = lockId;

                e = _context.CacheImpl.Get(key, ref lockId, ref lockDate, lockExpiration, accessType, operationContext);
                

                if (e == null && accessType == LockAccessType.ACQUIRE)
                {
                    if (lockId == null || generatedLockId.Equals(lockId))
                    {
                        lockId = null;
                        lockDate = new DateTime();
                    }
                }
                if (flagMap != null)
                {
                    
                    if (e != null)
                    {
                        /// increment the counter for hits/sec
                        _context.PerfStatsColl.MsecPerGetEndSample();
                        result.Value = e.Value;
                        result.Flag = e.Flag;
                    }

                }
                _context.PerfStatsColl.MsecPerGetEndSample();
                getTime.EndSample();
                
                /// update the counter for hits/sec or misses/sec
                if (result.Value != null)
                {
                    _context.PerfStatsColl.IncrementHitsRatioPerSecStats();
                    _context.PerfStatsColl.IncrementHitsPerSecStats();
                }
                else
                {
                    _context.PerfStatsColl.IncrementMissPerSecStats();
                }
                if (result.Value is CallbackEntry)
                    result.Value = ((CallbackEntry)result.Value).Value;
            }
            catch (OperationFailedException inner)
            {
                if (inner.IsTracable) _context.NCacheLog.Error("Cache.Get()", "Get operation failed. Error : " + inner.ToString());
                throw;
            }
            catch (Exception inner)
            {
                _context.NCacheLog.Error("Cache.Get()", "Get operation failed. Error : " + inner.ToString());
                throw new OperationFailedException("Get operation failed. Error :" + inner.Message, inner);
            }

            return result;
        }