/// <summary> /// Retrieve the object from the cache. A string key is passed as parameter. /// </summary> /// <param name="key">key of the entry.</param> /// <returns>cache entry.</returns> internal override CacheEntry GetInternal(object key, bool isUserOperation, OperationContext operationContext) { if (ServerMonitor.MonitorActivity) { ServerMonitor.LogClientActivity("LocalCache.Get", ""); } if (_cacheStore == null) { throw new InvalidOperationException(); } CacheEntry e = (CacheEntry)_cacheStore.Get(key); if (e != null) { EvictionHint evh = e.EvictionHint; if (isUserOperation && _evictionPolicy != null && evh != null && evh.IsVariant) { _evictionPolicy.Notify(key, evh, null); } } return(e); }
public void UpdateDirtyFlags(IList <long> toUpdate) { foreach (long rowId in toUpdate) { CacheItem citem = null; if (_cache.TryGetValue(rowId, out citem)) { citem.Flag.UnsetBit(BitsetConstants.DocumentDirty); citem.Flag.UnsetBit(BitsetConstants.MetaDataDirty); //Once item is persisted, it should be again added to the eviction policy if (!citem.Flag.IsAnyBitSet(BitsetConstants.MarkedForDeletion)) { _evictionPolicy.Notify(rowId, null, citem.EvictionHint); } } } }
public void Notify(object key, EvictionHint oldhint, EvictionHint newHint) { Sync.AcquireWriterLock(Timeout.Infinite); try { _evctPolicy.Notify(key, oldhint, newHint); } finally { Sync.ReleaseWriterLock(); } }
/// <summary> /// Retrieve the object from the cache. A string key is passed as parameter. /// </summary> /// <param name="key">key of the entry.</param> /// <returns>cache entry.</returns> internal override CacheEntry GetInternal(object key, bool isUserOperation, OperationContext operationContext, bool cloneEntry, bool needUserPayload) { if (_cacheStore == null) { throw new InvalidOperationException(); } CacheEntry e = (CacheEntry)_cacheStore.Get(key); if (e != null) { EvictionHint evh = e.EvictionHint; if (isUserOperation && _evictionPolicy != null && evh != null && evh.IsVariant) { _evictionPolicy.Notify(key, evh, null); } e.MarkInUse(NCModulesConstants.Global); if (cloneEntry) { e = e.DeepClone(operationContext.UseObjectPool? _context.TransactionalPoolManager: _context.FakeObjectPool, true); } } return(e); }
/// <summary> /// Método interno acionado para adicionar um novo item. /// </summary> /// <param name="key">Chave do item.</param> /// <param name="cacheEntry">Instancia da entrada que está sendo adicionada.</param> /// <param name="isUserOperation">True se for uma operação do usuário.</param> /// <returns>Resultado da operação.</returns> internal override CacheAddResult AddInternal(object key, CacheEntry cacheEntry, bool isUserOperation) { if (_cacheStore == null) { throw new InvalidOperationException(); } if (_evictionPolicy != null) { if (cacheEntry.EvictionHint is PriorityEvictionHint) { cacheEntry.Priority = ((PriorityEvictionHint)cacheEntry.EvictionHint).Priority; } cacheEntry.EvictionHint = _evictionPolicy.CompatibleHint(cacheEntry.EvictionHint); } StoreAddResult result = _cacheStore.Add(key, cacheEntry); if ((result == StoreAddResult.Success || result == StoreAddResult.SuccessNearEviction) && (_evictionPolicy != null)) { _evictionPolicy.Notify(key, null, cacheEntry.EvictionHint); } switch (result) { case StoreAddResult.Success: return(CacheAddResult.Success); case StoreAddResult.KeyExists: return(CacheAddResult.KeyExists); case StoreAddResult.NotEnoughSpace: return(CacheAddResult.NeedsEviction); case StoreAddResult.SuccessNearEviction: return(CacheAddResult.SuccessNearEviction); } return(CacheAddResult.Failure); }