コード例 #1
0
        /// <summary>
        /// Special purpose internal method. Derived classes don't override this method.
        /// </summary>
        /// <param name="key"></param>
        /// <param name="isUserOperation"></param>
        /// <returns></returns>
        internal override CacheEntry GetEntryInternal(object key, bool isUserOperation, OperationContext operationContext, bool cloneCacheEntry, bool needUserPayload)
        {
            if (ServerMonitor.MonitorActivity)
            {
                ServerMonitor.LogClientActivity("LocalCache.GetInternal", "");
            }

            if (_cacheStore == null)
            {
                throw new InvalidOperationException();
            }

            CacheEntry e = (CacheEntry)_cacheStore.Get(key);

            if (e == null)
            {
                return(e);
            }

            EvictionHint evh = e.EvictionHint;

            if (isUserOperation && _evictionPolicy != null && evh != null && evh.IsVariant)
            {
                _evictionPolicy.Notify(key, evh, null);
            }
            e.MarkInUse(NCModulesConstants.Global);

            if (cloneCacheEntry)
            {
                e = e.DeepClone(operationContext.UseObjectPool ? _context.TransactionalPoolManager : _context.FakeObjectPool);
            }

            return(e);
        }
コード例 #2
0
        /// <summary>
        /// Removes the object and key pair from the cache. The key is specified as parameter.
        /// Moreover it take a removal reason and a boolean specifying if a notification should
        /// be raised.
        /// </summary>
        /// <param name="key">key of the entry.</param>
        /// <param name="removalReason">reason for the removal.</param>
        /// <param name="notify">boolean specifying to raise the event.</param>
        /// <returns>item value</returns>
        internal override CacheEntry RemoveInternal(object key, ItemRemoveReason removalReason, bool isUserOperation, OperationContext operationContext, bool cloneEntry, bool needUserPayload)
        {
            if (_cacheStore == null)
            {
                throw new InvalidOperationException();
            }

            CacheEntry e = (CacheEntry)_cacheStore.Remove(key);

            if (e != null)
            {
                //Entry is no more part of store
                e.IsStored = false;

                if (_evictionPolicy != null && e.EvictionHint != null)
                {
                    _evictionPolicy.Remove(key, e.EvictionHint);
                }

                if (_notifyCacheFull)
                {
                    _notifyCacheFull = false;
                }

                if (cloneEntry)
                {
                    var clone = e.DeepClone(operationContext.UseObjectPool ? _context.TransactionalPoolManager : _context.FakeObjectPool, true);
                    //return entry to the store pool
                    MiscUtil.ReturnEntryToPool(e, _context.StorePoolManager);
                    e = clone;
                }
            }

            if (_context.PerfStatsColl != null)
            {
                if (_evictionPolicy != null)
                {
                    _context.PerfStatsColl.SetEvictionIndexSize((long)_evictionPolicy.IndexInMemorySize);
                }

                if (_context.ExpiryMgr != null)
                {
                    _context.PerfStatsColl.SetExpirationIndexSize((long)_context.ExpiryMgr.IndexInMemorySize);
                }
            }
            return(e);
        }