예제 #1
0
 /// <summary>
 /// Performs application-defined tasks associated with freeing, releasing, or
 /// resetting unmanaged resources.
 /// </summary>
 void IDisposable.Dispose()
 {
     lock (this)
     {
         if (_exh != null)
         {
             ((IDisposable)_exh).Dispose();
             _exh = null;
         }
         _evh = null;
     }
 }
예제 #2
0
 /// <summary>
 /// Ressincroniza o item de forma assincrona.
 /// </summary>
 /// <param name="key">Chave da entrada.</param>
 /// <param name="exh">Hint de expiração.</param>
 /// <param name="evh">Hint de liberação.</param>
 /// <param name="groupInfo">Informações do grupo.</param>
 /// <param name="queryInfo">Informações da consulta.</param>
 /// <param name="resyncProviderName">Nome do provedor de ressincronização.</param>
 /// <returns></returns>
 public object ResyncCacheItemAsync(object key, ExpirationHint exh, EvictionHint evh, GroupInfo groupInfo, Hashtable queryInfo, string resyncProviderName)
 {
     lock (_queue)
     {
         if ((_asyncProc != null) && (this.GetQueuedReadRequest(key) == null))
         {
             IAsyncTask evnt = new CacheResyncTask(this, key as string, exh, evh, _context.CompressionThreshold, groupInfo, queryInfo, resyncProviderName);
             _queue[key] = evnt;
             _asyncProc.Enqueue(evnt);
         }
         return(null);
     }
 }
예제 #3
0
 /// <summary>
 /// Construtor padrão.
 /// </summary>
 /// <param name="cache">Instancia do cache onde a entrada será adicionada.</param>
 /// <param name="key">Chave da entrada.</param>
 /// <param name="value">Valor da entrada.</param>
 /// <param name="expiryHint">Hint de expiração.</param>
 /// <param name="syncDependency">Dependencia de sincronização.</param>
 /// <param name="evictionHint">Hint de liberação</param>
 /// <param name="group"></param>
 /// <param name="subGroup"></param>
 /// <param name="Flag"></param>
 /// <param name="queryInfo"></param>
 /// <param name="operationContext"></param>
 public AsyncAdd(Cache cache, object key, object value, ExpirationHint expiryHint, CacheSyncDependency syncDependency, EvictionHint evictionHint, string group, string subGroup, BitSet Flag, Hashtable queryInfo, OperationContext operationContext)
 {
     _cache            = cache;
     _key              = key;
     _value            = value;
     _expiryHint       = expiryHint;
     _syncDependency   = syncDependency;
     _evictionHint     = evictionHint;
     _group            = group;
     _subGroup         = subGroup;
     _flag             = Flag;
     _queryInfo        = queryInfo;
     _operationContext = operationContext;
 }
예제 #4
0
 /// <summary>
 /// Libera a instancia.
 /// </summary>
 /// <param name="disposing"></param>
 protected virtual void Dispose(bool disposing)
 {
     lock (this)
     {
         if (_expirationHint != null)
         {
             ((IDisposable)_expirationHint).Dispose();
             if (((this.KeysIAmDependingOn == null) || (this.KeysIAmDependingOn.Length == 0)) && ((this.KeysDependingOnMe == null) || (this.KeysDependingOnMe.Count == 0)))
             {
                 _expirationHint = null;
             }
         }
         _evictionHint = null;
     }
 }
예제 #5
0
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or
        /// resetting unmanaged resources.
        /// </summary>
        void IDisposable.Dispose()
        {
            lock (this)
            {
                if (_exh != null)
                {
                    ((IDisposable)_exh).Dispose();

                    if ((this.KeysIAmDependingOn == null || this.KeysIAmDependingOn.Length == 0) && (this.KeysDependingOnMe == null || this.KeysDependingOnMe.Count == 0))
                    {
                        _exh = null;
                    }
                }
                _evh = null;
            }
        }
예제 #6
0
파일: CacheEntry.cs 프로젝트: yaobos/NCache
 void ICompactSerializable.Serialize(CompactWriter writer)
 {
     lock (this)
     {
         writer.WriteObject(Value);
         writer.Write(_bitset.Data);
         EvictionHint.WriteEvcHint(writer, _evh);
         ExpirationHint.WriteExpHint(writer, _exh);
         writer.WriteObject(_queryInfo);
         writer.Write(_size);
         writer.WriteObject(lockMetaInfo);
         writer.Write(_creationTime);
         writer.Write(_lastModifiedTime);
         writer.Write((int)_priorityValue);
         writer.WriteObject(this._type);
     }
 }
예제 #7
0
파일: CacheEntry.cs 프로젝트: yaobos/NCache
 void ICompactSerializable.Deserialize(CompactReader reader)
 {
     lock (this)
     {
         Value             = reader.ReadObject();
         _bitset           = new BitSet(reader.ReadByte());
         _evh              = EvictionHint.ReadEvcHint(reader);
         _exh              = ExpirationHint.ReadExpHint(reader);
         _queryInfo        = (Hashtable)reader.ReadObject();
         _size             = reader.ReadInt64();
         lockMetaInfo      = reader.ReadObject() as LockMetaInfo;
         _creationTime     = reader.ReadDateTime();
         _lastModifiedTime = reader.ReadDateTime();
         _priorityValue    = (CacheItemPriority)reader.ReadInt32();
         _type             = reader.ReadObject() as string;
     }
 }
예제 #8
0
        internal override CacheEntry GetInternal(object key, bool isUserOperation, OperationContext operationContext)
        {
            if (_cacheStore == null)
            {
                throw new InvalidOperationException();
            }
            CacheEntry entry = (CacheEntry)_cacheStore.Get(key);

            if (entry != null)
            {
                EvictionHint evictionHint = entry.EvictionHint;
                if ((isUserOperation && (_evictionPolicy != null)) && ((evictionHint != null) && evictionHint.IsVariant))
                {
                    _evictionPolicy.Notify(key, evictionHint, null);
                }
            }
            return(entry);
        }
예제 #9
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="cache"></param>
 /// <param name="key"></param>
 /// <param name="value"></param>
 /// <param name="expiryHint"></param>
 /// <param name="evictionHint"></param>
 public AsyncInsert(Cache cache, object key, object value,
                    ExpirationHint expiryHint,
                    EvictionHint evictionHint,
                    string group, string subGroup, BitSet Flag, Hashtable queryInfo, string provider, OperationContext operationContext, Notifications notification, string typeName)
 {
     _cache        = cache;
     _key          = key;
     _value        = value;
     _expiryHint   = expiryHint;
     _evictionHint = evictionHint;
     _group        = group;
     _subGroup     = subGroup;
     _flag         = new BitSet()
     {
         Data = Flag.Data
     };
     _queryInfo        = queryInfo;
     _provider         = provider;
     _cbEntry          = notification;
     _operationContext = operationContext;
     _type             = typeName;
 }
예제 #10
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)
        {
            try
            {
                if (cacheEntry != null)
                {
                    cacheEntry.MarkInUse(NCModulesConstants.LocalCache);
                }

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

                if (oldEntry != null && cacheEntry.Type != oldEntry.Type)
                {
                    throw new Exception(string.Format("Cannot update '{0}' type with '{1}' type.", oldEntry.Type, cacheEntry.Type));
                }

                if (cacheEntry.EvictionHint is PriorityEvictionHint)
                {
                    cacheEntry.Priority = ((PriorityEvictionHint)cacheEntry.EvictionHint).Priority;
                }

                if (_evictionPolicy != null)
                {
                    EvictionHint oldEvictionHint = cacheEntry.EvictionHint;

                    cacheEntry.EvictionHint = _evictionPolicy.CompatibleHint(cacheEntry.EvictionHint, _context.StorePoolManager);

                    if (oldEvictionHint != null && !ReferenceEquals(oldEvictionHint, cacheEntry.EvictionHint))
                    {
                        MiscUtil.ReturnEvictionHintToPool(oldEvictionHint, _context.StorePoolManager);
                    }
                }

                EvictionHint peEvh = oldEntry == null ? null : oldEntry.EvictionHint;

                // No Need to insert Eviction if Eviction is turned off it will reduce cache-entry overhead
                if (_evictionPolicy == null)
                {
                    cacheEntry.EvictionHint = null;
                }

                CacheEntry storedEntry = _cacheStore.Get(key) as CacheEntry;

                StoreInsResult result = _cacheStore.Insert(key, cacheEntry, !isUserOperation);

                // Operation completed!
                if (result == StoreInsResult.Success || result == StoreInsResult.SuccessNearEviction)
                {
                    //This means that entry has become part of the store
                    cacheEntry.IsStored = true;
                    if (_evictionPolicy != null)
                    {
                        _evictionPolicy.Notify(key, null, cacheEntry.EvictionHint);
                    }

                    if (!object.ReferenceEquals(storedEntry, cacheEntry))
                    {
                        MiscUtil.ReturnEntryToPool(storedEntry, _context.StorePoolManager);
                    }
                }
                else if (result == StoreInsResult.SuccessOverwrite || result == StoreInsResult.SuccessOverwriteNearEviction)
                {
                    if (!object.ReferenceEquals(storedEntry, cacheEntry))
                    {
                        MiscUtil.ReturnEntryToPool(storedEntry, _context.StorePoolManager);
                    }
                    //This means that entry has become part of the store
                    cacheEntry.IsStored = true;

                    if (oldEntry != null)
                    {
                        //update the cache item version...
                        if (isUserOperation)
                        {
                            cacheEntry.UpdateVersion(oldEntry);
                        }

                        //update the cache item last modifeid time...
                        cacheEntry.UpdateLastModifiedTime(oldEntry);
                    }

                    if (_evictionPolicy != null)
                    {
                        _evictionPolicy.Notify(key, peEvh, cacheEntry.EvictionHint);
                    }
                }
                if (result == StoreInsResult.NotEnoughSpace && !_notifyCacheFull)
                {
                    _notifyCacheFull = true;
                    _context.NCacheLog.Error("LocalCache.InsertInternal", "The cache is full and not enough items could be evicted.");
                }

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

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

                switch (result)
                {
                case StoreInsResult.Success: return(CacheInsResult.Success);

                case StoreInsResult.SuccessOverwrite: return(CacheInsResult.SuccessOverwrite);

                case StoreInsResult.NotEnoughSpace: return(CacheInsResult.NeedsEviction);

                case StoreInsResult.SuccessNearEviction: return(CacheInsResult.SuccessNearEvicition);

                case StoreInsResult.SuccessOverwriteNearEviction: return(CacheInsResult.SuccessOverwriteNearEviction);
                }

                return(CacheInsResult.Failure);
            }
            finally
            {
                if (cacheEntry != null)
                {
                    cacheEntry.MarkFree(NCModulesConstants.LocalCache);
                }
            }
        }
예제 #11
0
        /// <summary>
        /// Adds a pair of key and value to the cache. Throws an exception or reports error
        /// if the specified key already exists in 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 CacheAddResult AddInternal(object key, CacheEntry cacheEntry, bool isUserOperation, OperationContext operationContext)
        {
            try
            {
                if (_cacheStore == null)
                {
                    throw new InvalidOperationException();
                }
                if (cacheEntry != null)
                {
                    cacheEntry.MarkInUse(NCModulesConstants.LocalCache);
                }

                if (_evictionPolicy != null)
                {
                    if (cacheEntry.EvictionHint is PriorityEvictionHint)
                    {
                        cacheEntry.Priority = ((PriorityEvictionHint)cacheEntry.EvictionHint).Priority;
                    }

                    EvictionHint oldEvictionHint = cacheEntry.EvictionHint;

                    cacheEntry.EvictionHint = _evictionPolicy.CompatibleHint(cacheEntry.EvictionHint, _context.StorePoolManager);

                    if (oldEvictionHint != null && !ReferenceEquals(oldEvictionHint, cacheEntry.EvictionHint))
                    {
                        MiscUtil.ReturnEvictionHintToPool(oldEvictionHint, _context.StorePoolManager);
                    }
                }

                // No Need to insert Eviction if Eviction is turned off it will reduce cache-entry overhead

                if (_evictionPolicy == null)
                {
                    cacheEntry.EvictionHint = null;
                }

                StoreAddResult result = _cacheStore.Add(key, cacheEntry, !isUserOperation);
                if (result == StoreAddResult.Success || result == StoreAddResult.SuccessNearEviction)
                {
                    cacheEntry.IsStored = true;
                    if (_evictionPolicy != null)
                    {
                        _evictionPolicy.Notify(key, null, cacheEntry.EvictionHint);
                    }
                }
                if (result == StoreAddResult.NotEnoughSpace && !_notifyCacheFull)
                {
                    _notifyCacheFull = true;
                    _context.NCacheLog.Error("LocalCache.AddInternal", "The cache is full and not enough items could be evicted.");
                }

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

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

                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);
            }
            finally
            {
                if (cacheEntry != null)
                {
                    cacheEntry.MarkFree(NCModulesConstants.LocalCache);
                }
            }
        }
예제 #12
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 (ServerMonitor.MonitorActivity)
            {
                ServerMonitor.LogClientActivity("LocalCache.Insert", "");
            }

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

            if (cacheEntry.EvictionHint is PriorityEvictionHint)
            {
                cacheEntry.Priority = ((PriorityEvictionHint)cacheEntry.EvictionHint).Priority;
            }

            if (_evictionPolicy != null)
            {
                cacheEntry.EvictionHint = _evictionPolicy.CompatibleHint(cacheEntry.EvictionHint);
            }

            EvictionHint peEvh = oldEntry == null ? null : oldEntry.EvictionHint;

            // No Need to insert Eviction if Eviction is turned off it will reduce cache-entry overhead

            if (_evictionPolicy == null)
            {
                cacheEntry.EvictionHint = null;
            }

            //

            StoreInsResult result = _cacheStore.Insert(key, cacheEntry, !isUserOperation);

            // Operation completed!
            if (result == StoreInsResult.Success || result == StoreInsResult.SuccessNearEviction)
            {
                if (_evictionPolicy != null)
                {
                    _evictionPolicy.Notify(key, null, cacheEntry.EvictionHint);
                }
            }
            else if (result == StoreInsResult.SuccessOverwrite || result == StoreInsResult.SuccessOverwriteNearEviction)
            {
                //update the cache item last modifeid time...
                cacheEntry.UpdateLastModifiedTime(oldEntry);

                if (_evictionPolicy != null)
                {
                    _evictionPolicy.Notify(key, peEvh, cacheEntry.EvictionHint);
                }
            }
            if (result == StoreInsResult.NotEnoughSpace && !_notifyCacheFull)
            {
                _notifyCacheFull = true;
                _context.NCacheLog.Error("LocalCache.InsertInternal", "The cache is full and not enough items could be evicted.");
            }

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

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

            switch (result)
            {
            case StoreInsResult.Success: return(CacheInsResult.Success);

            case StoreInsResult.SuccessOverwrite: return(CacheInsResult.SuccessOverwrite);

            case StoreInsResult.NotEnoughSpace: return(CacheInsResult.NeedsEviction);

            case StoreInsResult.SuccessNearEviction: return(CacheInsResult.SuccessNearEvicition);

            case StoreInsResult.SuccessOverwriteNearEviction: return(CacheInsResult.SuccessOverwriteNearEviction);
            }
            return(CacheInsResult.Failure);
        }
예제 #13
0
 public OpenStreamOperation(string key, string lockHandle, StreamModes mode, string group, string subGroup, ExpirationHint expHint, EvictionHint evHint, OperationContext operationContext)
 {
     _key              = key;
     _group            = group;
     _subGroup         = subGroup;
     _expHint          = expHint;
     _evictionHint     = evHint;
     _mode             = mode;
     _lockHandle       = lockHandle;
     _operationContext = operationContext;
 }
예제 #14
0
 public CacheItem()
 {
     _evictionHint = new TimestampHint();
 }
예제 #15
0
 /// <summary>
 /// Construtor padrão.
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="key"></param>
 /// <param name="exh"></param>
 /// <param name="evh"></param>
 /// <param name="compressionThreshold"></param>
 /// <param name="groupInfo"></param>
 /// <param name="queryInfo"></param>
 /// <param name="resyncProviderName"></param>
 public CacheResyncTask(DatasourceMgr parent, string key, ExpirationHint exh, EvictionHint evh, long compressionThreshold, GroupInfo groupInfo, Hashtable queryInfo, string resyncProviderName)
 {
     _parent             = parent;
     _key                = key;
     _exh                = exh;
     _evh                = evh;
     _groupInfo          = groupInfo;
     _queryInfo          = queryInfo;
     _resyncProviderName = resyncProviderName;
 }
예제 #16
0
 public virtual bool OpenStream(string key, string lockHandle, StreamModes mode, string group, string subGroup, ExpirationHint hint, EvictionHint evictinHint, OperationContext operationContext)
 {
     return(false);
 }
예제 #17
0
 public override bool OpenStream(string key, string lockHandle, StreamModes mode, string group, string subGroup, ExpirationHint hint, EvictionHint evictinHint, OperationContext operationContext)
 {
     try
     {
         base.Sync.AcquireWriterLock(-1);
         return(this.InternalCache.OpenStream(key, lockHandle, mode, group, subGroup, hint, evictinHint, operationContext));
     }
     finally
     {
         base.Sync.ReleaseWriterLock();
     }
 }
예제 #18
0
        public override bool OpenStream(string key, string lockHandle, StreamModes mode, string group, string subGroup, ExpirationHint hint, EvictionHint evictinHint, OperationContext operationContext)
        {
            object[] keyDependencyTable = CacheHelper.GetKeyDependencyTable(hint);
            if ((keyDependencyTable != null) && (mode == StreamModes.Write))
            {
                Hashtable hashtable = this.Contains(keyDependencyTable, operationContext);
                if (!hashtable.ContainsKey("items-found"))
                {
                    throw new OperationFailedException("One of the dependency keys does not exist.");
                }
                if (hashtable["items-found"] == null)
                {
                    throw new OperationFailedException("One of the dependency keys does not exist.");
                }
                if (((ArrayList)hashtable["items-found"]).Count != keyDependencyTable.Length)
                {
                    throw new OperationFailedException("One of the dependency keys does not exist.");
                }
            }
            bool flag = this.Internal.OpenStream(key, lockHandle, mode, group, subGroup, hint, evictinHint, operationContext);

            if ((flag && (mode == StreamModes.Write)) && (keyDependencyTable != null))
            {
                Hashtable table = new Hashtable();
                for (int i = 0; i < keyDependencyTable.Length; i++)
                {
                    if (table[keyDependencyTable[i]] == null)
                    {
                        table.Add(keyDependencyTable[i], new ArrayList());
                    }
                    ((ArrayList)table[keyDependencyTable[i]]).Add(key);
                }
                this.Internal.AddDependencyKeyList(table, operationContext);
            }
            return(flag);
        }