示例#1
0
        /// <summary>
        /// Adds a pair of key and value to the cache. If the specified key already exists
        /// in the cache; it is updated, otherwise a new item is added to the cache.
        /// </summary>
        /// <param name="key">key of the entry.</param>
        /// <param name="cacheEntry">the cache entry.</param>
        /// <returns>returns the result of operation.</returns>
        internal override CacheInsResult InsertInternal(object key, CacheEntry cacheEntry, bool isUserOperation, CacheEntry oldEntry, OperationContext operationContext, bool updateIndex)
        {
            CacheInsResult result = base.InsertInternal(key, cacheEntry, isUserOperation, oldEntry, operationContext, updateIndex);

            if (result == CacheInsResult.Success || result == CacheInsResult.SuccessNearEvicition)
            {
                if (_queryIndexManager != null && cacheEntry.QueryInfo != null)
                {
                    _queryIndexManager.AddToIndex(key, cacheEntry, operationContext);
                }
            }
            else if ((result == CacheInsResult.SuccessOverwrite || result == CacheInsResult.SuccessOverwriteNearEviction) && updateIndex)
            {
                if (_queryIndexManager != null)
                {
                    if (oldEntry != null && oldEntry.ObjectType != null)
                    {
                        _queryIndexManager.RemoveFromIndex(key, oldEntry);
                    }

                    if (cacheEntry.QueryInfo != null)
                    {
                        _queryIndexManager.AddToIndex(key, cacheEntry, operationContext);
                    }
                }
            }

            if (_context.PerfStatsColl != null && _queryIndexManager != null)
            {
                _context.PerfStatsColl.SetQueryIndexSize(_queryIndexManager.IndexInMemorySize);
            }

            return(result);
        }
示例#2
0
        /// <summary>
        /// Adds a pair of key and value to the cache. If the specified key already exists
        /// in the cache; it is updated, otherwise a new item is added to the cache.
        /// </summary>
        /// <param name="key">key of the entry.</param>
        /// <param name="cacheEntry">the cache entry.</param>
        /// <returns>returns the result of operation.</returns>
        internal override CacheInsResult InsertInternal(object key, CacheEntry cacheEntry, bool isUserOperation, CacheEntry oldEntry, OperationContext operationContext, bool updateIndex)
        {
            if (oldEntry != null)
            {
                if (!Util.CacheHelper.CheckDataGroupsCompatibility(cacheEntry.GroupInfo, oldEntry.GroupInfo))
                {
                    return(CacheInsResult.IncompatibleGroup);// throw new Exception("Data group of the inserted item does not match the existing item's data group");
                }
            }

            CacheInsResult result = base.InsertInternal(key, cacheEntry, isUserOperation, oldEntry, operationContext, updateIndex);

            if (result == CacheInsResult.Success || result == CacheInsResult.SuccessNearEvicition)
            {
                _grpIndexManager.AddToGroup(key, cacheEntry.GroupInfo);


                if (_queryIndexManager != null && cacheEntry.QueryInfo != null)
                {
                    _queryIndexManager.AddToIndex(key, cacheEntry, operationContext);
                }
            }
            else if ((result == CacheInsResult.SuccessOverwrite || result == CacheInsResult.SuccessOverwriteNearEviction) && updateIndex)
            {
                if (oldEntry != null)
                {
                    _grpIndexManager.RemoveFromGroup(key, oldEntry.GroupInfo);
                }
                _grpIndexManager.AddToGroup(key, cacheEntry.GroupInfo);


                if (_queryIndexManager != null)
                {
                    if (oldEntry != null && oldEntry.ObjectType != null)
                    {
                        _queryIndexManager.RemoveFromIndex(key, oldEntry);
                    }

                    if (cacheEntry.QueryInfo != null)
                    {
                        _queryIndexManager.AddToIndex(key, cacheEntry, operationContext);
                    }
                }
            }

            if (_context.PerfStatsColl != null)
            {
                if (_queryIndexManager != null)
                {
                    _context.PerfStatsColl.SetQueryIndexSize(_queryIndexManager.IndexInMemorySize);
                }

                _context.PerfStatsColl.SetGroupIndexSize(_grpIndexManager.IndexInMemorySize);
            }

            return(result);
        }
示例#3
0
        /// <summary>
        /// Método interno usado para inserir uma nova entrada no cache.
        /// </summary>
        /// <param name="key">Chave que representa a entrada.</param>
        /// <param name="cacheEntry">Instancia da entrada.</param>
        /// <param name="isUserOperation">True se for uma operação do usuário.</param>
        /// <param name="oldEntry">Valor da antiga entrada.</param>
        /// <param name="operationContext">Contexto da operação.</param>
        /// <returns>Resulta da operação.</returns>
        internal override CacheInsResult InsertInternal(object key, CacheEntry cacheEntry, bool isUserOperation, CacheEntry oldEntry, OperationContext operationContext)
        {
            if (oldEntry != null && !CacheHelper.CheckDataGroupsCompatibility(cacheEntry.GroupInfo, oldEntry.GroupInfo))
            {
                return(CacheInsResult.IncompatibleGroup);
            }
            CacheInsResult result = base.InsertInternal(key, cacheEntry, isUserOperation, oldEntry, operationContext);

            switch (result)
            {
            case CacheInsResult.Success:
            case CacheInsResult.SuccessNearEvicition:
                _grpIndexManager.AddToGroup(key, cacheEntry.GroupInfo);
                if ((_queryIndexManager != null) && (cacheEntry.QueryInfo != null))
                {
                    _queryIndexManager.AddToIndex(key, cacheEntry);
                }
                return(result);

            case CacheInsResult.SuccessOverwrite:
            case CacheInsResult.SuccessOverwriteNearEviction:
                if (oldEntry != null)
                {
                    _grpIndexManager.RemoveFromGroup(key, oldEntry.GroupInfo);
                }
                _grpIndexManager.AddToGroup(key, cacheEntry.GroupInfo);
                if (_queryIndexManager == null)
                {
                    return(result);
                }
                if (oldEntry != null && oldEntry.QueryInfo != null)
                {
                    _queryIndexManager.RemoveFromIndex(key, oldEntry.QueryInfo);
                }
                if (cacheEntry.QueryInfo != null)
                {
                    _queryIndexManager.AddToIndex(key, cacheEntry);
                }
                break;
            }
            return(result);
        }