示例#1
0
 public void ResetVariant(ExpirationHint hint)
 {
     lock (this)
     {
         hint.ResetVariant(_context);
     }
 }
示例#2
0
        internal static ExpirationHint GetExpirationHint(PoolManager poolManager, object dependency, DateTime absoluteExpiration, TimeSpan slidingExpiration)
        {
            ExpirationHint hint = GetExpirationHint(poolManager, absoluteExpiration, slidingExpiration);

            if (hint == null)
            {
                return(GetExpirationHint(poolManager));
            }

            ExpirationHint hint2 = GetExpirationHint(poolManager);

            if (hint2 == null)
            {
                return(hint);
            }


            AggregateExpirationHint aggregateHint = null;

            if (hint2 is AggregateExpirationHint)
            {
                aggregateHint = hint2 as AggregateExpirationHint;
                aggregateHint.Add(hint);

                return(aggregateHint);
            }

            aggregateHint = AggregateExpirationHint.Create(poolManager);
            aggregateHint.Add(hint);
            aggregateHint.Add(hint2);

            return(aggregateHint);
        }
示例#3
0
        public static ExpirationHint ReadExpHint(CompactReader reader)
        {
            ExpirationHintType expHint = ExpirationHintType.Parent;

            expHint = (ExpirationHintType)reader.ReadInt16();
            ExpirationHint tmpObj = null;

            switch (expHint)
            {
            case ExpirationHintType.NULL:
                return(null);

            case ExpirationHintType.Parent:
                tmpObj = (ExpirationHint)reader.ReadObject();
                return((ExpirationHint)tmpObj);

            case ExpirationHintType.FixedExpiration:
                FixedExpiration fe = new FixedExpiration();
                ((ICompactSerializable)fe).Deserialize(reader);
                return((ExpirationHint)fe);

            case ExpirationHintType.IdleExpiration:
                IdleExpiration ie = new IdleExpiration();
                ((ICompactSerializable)ie).Deserialize(reader);
                return((ExpirationHint)ie);

            default:
                break;
            }
            return(null);
        }
示例#4
0
        public static ExpirationHint GetExpirationHint(ExpirationPolicy policy, CacheDependency dependency, DateTime absoluteExpiration, TimeSpan slidingExpiration)
        {
            ExpirationHint hint = GetExpirationHint(policy, absoluteExpiration, slidingExpiration);

            if (hint == null)
            {
                return(GetExpirationHint(dependency));
            }

            ExpirationHint hint2 = GetExpirationHint(dependency);

            if (hint2 == null)
            {
                return(hint);
            }


            AggregateExpirationHint aggregateHint = null;

            if (hint2 is AggregateExpirationHint)
            {
                aggregateHint = hint2 as AggregateExpirationHint;
                aggregateHint.Add(hint);

                return(aggregateHint);
            }

            aggregateHint = new AggregateExpirationHint();
            aggregateHint.Add(hint);
            aggregateHint.Add(hint2);

            return(aggregateHint);
        }
示例#5
0
        internal AggregateExpirationHint GetRoutableClone(Address sourceNode)
        {
            if (_hints == null || _hints.Count == 0)
            {
                return(null);
            }

            AggregateExpirationHint hint = new AggregateExpirationHint();

            NodeExpiration ne = null;

            for (int i = 0; i < _hints.Count; i++)
            {
                ExpirationHint eh = (ExpirationHint)_hints[i];
                if (!eh.IsRoutable && ne == null)
                {
                    ne = new NodeExpiration(sourceNode);
                    hint.Add(ne);
                }
                else
                {
                    hint.Add(eh);
                }
            }
            return(hint);
        }
        internal AggregateExpirationHint GetRoutableClone(PoolManager poolManager, Address sourceNode)
        {
            if (_hints == null || _hints.Count == 0)
            {
                return(null);
            }

            AggregateExpirationHint hint = Create(poolManager);

            NodeExpiration ne = null;

            for (int i = 0; i < _hints.Count; i++)
            {
                ExpirationHint eh = (ExpirationHint)_hints[i];
                if (!eh.IsRoutable && ne == null)
                {
                    ne = NodeExpiration.Create(poolManager, sourceNode);
                    hint.Add(ne);
                }
                else
                {
                    hint.Add(eh);
                }
            }
            return(hint);
        }
示例#7
0
 public void AddDBMapping(string dbKey, string cacheKey, ExpirationHint hint)
 {
     lock (_dbKeysMappingTbl.SyncRoot)
     {
         _dbKeysMappingTbl[dbKey] = new DependencyInformation(cacheKey, hint);
     }
 }
示例#8
0
        public void RemoveFromIndex(object key)
        {
            lock (_status_mutex)
            {
                int removeSize = 0;

                if (!IsInProgress)
                {
                    ExpirationHint expHint = _mainIndex[key] as ExpirationHint;
                    if (expHint != null)
                    {
                        removeSize = expHint.InMemorySize;
                    }
                    _mainIndex.Remove(key);
                }
                else
                {
                    //Adding a with null value indicates that this key has been
                    //removed so we should remove it from the main index.

                    ExpirationHint expHint = _transitoryIndex[key] as ExpirationHint;
                    if (expHint != null)
                    {
                        removeSize = expHint.InMemorySize;
                    }

                    _transitoryIndex[key] = null;
                }
                _expirationManagerSize -= removeSize;
            }
        }
        public override void ResetLeasable()
        {
            base.ResetLeasable();

            _hints?.Clear();
            _expiringHint = null;
            _hintType     = ExpirationHintType.AggregateExpirationHint;
        }
示例#10
0
        public static void WriteExpHint(CompactWriter writer, ExpirationHint expHint)
        {
            if (expHint == null)
            {
                writer.Write((short)ExpirationHintType.NULL);
                return;
            }

            writer.Write((short)expHint._hintType);
            ((ICompactSerializable)expHint).Serialize(writer);
        }
示例#11
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="val">the object to be added to the cache</param>
        /// <param name="expiryHint">expiration hint for the object</param>
        /// <param name="evictionHint">eviction hint for the object</param>
        internal CacheEntry(object val, ExpirationHint expiryHint, EvictionHint evictionHint)
            : base(val)
        {
            _exh = expiryHint;
            _evh = evictionHint;
            
            _bitset.SetBit(FLATTENED);

            _creationTime = System.DateTime.Now;
            _lastModifiedTime = System.DateTime.Now;
        }
示例#12
0
 /// <summary>
 /// Resets only the variant ExpirationHints.
 /// </summary>
 internal override void ResetVariant(CacheRuntimeContext context)
 {
     for (int i = 0; i < _hints.Count; i++)
     {
         ExpirationHint hint = (ExpirationHint)_hints[i];
         if (hint.IsVariant)
         {
             hint.Reset(context);
         }
     }
 }
示例#13
0
        protected override void DeepCloneInternal(PoolManager poolManager, ExpirationHint clonedHint)
        {
            if (clonedHint == null)
                return;

            base.DeepCloneInternal(poolManager, clonedHint);

            if (clonedHint is DependencyHint clonedDependencyHint)
            {
                clonedDependencyHint._startAfter = _startAfter;
            }
        }
示例#14
0
        protected virtual void DeepCloneInternal(PoolManager poolManager, ExpirationHint clonedHint)
        {
            if (clonedHint == null)
            {
                return;
            }

            clonedHint._bits      = _bits;
            clonedHint._cacheKey  = _cacheKey;
            clonedHint._hintType  = _hintType;
            clonedHint._objNotify = _objNotify;
            clonedHint._ncacheLog = _ncacheLog;
        }
示例#15
0
 public static void GetActualCacheDependency(ExpirationHint hint, ref DateTime absoluteExpiration, ref TimeSpan slidingExpiration)
 {
     if (hint != null)
     {
         if (hint is FixedExpiration)
         {
             absoluteExpiration = ((FixedExpiration)hint).AbsoluteTime;
         }
         else if (hint is IdleExpiration)
         {
             slidingExpiration = ((IdleExpiration)hint).SlidingTime;
         }
     }
 }
示例#16
0
 /// <summary>
 /// Initialize the new hint. if no new hint is specified then dispose the old hint.
 /// </summary>
 /// <param name="oldHint"></param>
 /// <param name="newHint"></param>
 public void ResetHint(ExpirationHint oldHint, ExpirationHint newHint)
 {
     lock (this)
     {
         if (newHint != null)
         {
             if (oldHint != null)
             {
                 ((IDisposable)oldHint).Dispose();                  //dispose only if newHint is not null
             }
             newHint.Reset(_context);
         }
     }
 }
示例#17
0
 public static void GetActualCacheDependency(ExpirationHint hint, ref DateTime absoluteExpiration, ref TimeSpan slidingExpiration)
 {
     if (hint != null)
     {
         if (hint is FixedExpiration)
         {
             absoluteExpiration = ((FixedExpiration)hint).AbsoluteTime;
         }
         else if (hint is IdleExpiration)
         {
             slidingExpiration = ((IdleExpiration)hint).SlidingTime;
         }
     }
 }
示例#18
0
        protected sealed override void DeepCloneInternal(PoolManager poolManager, ExpirationHint clonedHint)
        {
            if (clonedHint == null)
            {
                return;
            }

            base.DeepCloneInternal(poolManager, clonedHint);

            if (clonedHint is NodeExpiration clonedNodeExpirationHint)
            {
                clonedNodeExpirationHint._node = _node.Clone() as Address;
            }
        }
示例#19
0
        protected sealed override void DeepCloneInternal(PoolManager poolManager, ExpirationHint clonedHint)
        {
            if (clonedHint == null)
            {
                return;
            }

            base.DeepCloneInternal(poolManager, clonedHint);

            if (clonedHint is IdleExpiration clonedIdleExpirationHint)
            {
                clonedIdleExpirationHint._lastTimeStamp  = _lastTimeStamp;
                clonedIdleExpirationHint._idleTimeToLive = _idleTimeToLive;
            }
        }
示例#20
0
 public CompactCacheEntry(object key, object value, ExpirationHint dependency, 
     long expiration, 
     byte options, object itemRemovedCallback, Hashtable queryInfo, BitSet Flag, object lockId, LockAccessType accessType)
 {
     _key = key;
     _flag = Flag;
     _value = value;
     _dependency = dependency;
     _expiration = expiration;
     _options = options;
     _itemRemovedCallback = itemRemovedCallback;
     _queryInfo = queryInfo;
     _lockId = lockId;
     _accessType = accessType;
 }
示例#21
0
        protected sealed override void DeepCloneInternal(PoolManager poolManager, ExpirationHint clonedHint)
        {
            if (clonedHint == null)
            {
                return;
            }

            base.DeepCloneInternal(poolManager, clonedHint);

            if (clonedHint is FixedExpiration clonedFixedExpirationHint)
            {
                clonedFixedExpirationHint._absoluteTime = _absoluteTime;
                clonedFixedExpirationHint._milliseconds = _milliseconds;
            }
        }
示例#22
0
        /// <summary>
        /// Add an expiration hint to the hints
        /// </summary>
        /// <param name="eh"></param>
        public void Add(ExpirationHint eh)
        {
            lock (this)
            {
                if (!eh.IsRoutable)
                {
                    this.SetBit(NON_ROUTABLE);
                }
                if (eh.IsVariant)
                {
                    this.SetBit(IS_VARIANT);
                }
                eh.SetExpirationEventSink(this);

                AggregateExpirationHint aggregate = eh as AggregateExpirationHint;
                if (aggregate != null)
                {
                    foreach (ExpirationHint expirationHint in aggregate._hints)
                    {
                        _hints.Add(expirationHint);
                    }
                }
                else
                {
                    _hints.Add(eh);
                }

                bool isFixed = false;
                for (int i = _hints.Count - 1; i >= 0; i--)
                {
                    if (isFixed && _hints[i] is FixedExpiration)
                    {
                        var previousFixedExpiration = _hints[i];
                        _hints.RemoveAt(i);
                        previousFixedExpiration.ReturnLeasableToPool();

                        break;
                    }
                    if (!isFixed && _hints[i] is FixedExpiration)
                    {
                        isFixed = true;
                    }
                }
            }
        }
示例#23
0
 public CacheDependency GetActualCacheDependency(ExpirationHint hint, ref DateTime absoluteExpiration, ref TimeSpan slidingExpiration)
 {
     if (hint != null)
     {
         if (hint is AggregateExpirationHint)
         {
             AggregateExpirationHint aggregate = (AggregateExpirationHint)hint;
             IList <ExpirationHint>  hints     = aggregate.Hints;
             if (hints != null && hints.Count > 0)
             {
                 foreach (ExpirationHint h in hints)
                 {
                     CacheDependency cacheDep = GetActualCacheDependency(h, ref absoluteExpiration, ref slidingExpiration);
                     if (cacheDep != null && !(cacheDep is Runtime.Dependencies.AggregateCacheDependency))
                     {
                         aggregateList.Add(cacheDep);
                     }
                 }
                 if (aggregateList.Count >= 2)
                 {
                     Runtime.Dependencies.AggregateCacheDependency aggDep = new Runtime.Dependencies.AggregateCacheDependency();
                     aggDep.Add(aggregateList.ToArray());
                     return(aggDep);
                 }
                 else
                 {
                     return(aggregateList[0]);
                 }
             }
         }
         else if (hint is FixedExpiration)
         {
             absoluteExpiration = ((FixedExpiration)hint).AbsoluteTime;
         }
         else if (hint is IdleExpiration)
         {
             slidingExpiration = ((IdleExpiration)hint).SlidingTime;
         }
         else
         {
             return(GetNonAggregateDependencies(hint));
         }
     }
     return(null);
 }
示例#24
0
        public static void WriteExpHint(CompactWriter writer, ExpirationHint expHint)
        {
            if (expHint == null)
            {
                writer.Write((short)ExpirationHintType.NULL);
                return;
            }

            writer.Write((short)expHint._hintType);
            if (expHint._hintType == ExpirationHintType.ExtensibleDependency)
            {
                writer.WriteObject(expHint);
            }
            else
            {
                ((ICompactSerializable)expHint).Serialize(writer);
            }

            return;
        }
示例#25
0
        public static ExpirationHint GetExpirationHint(DateTime absoluteExpiration, TimeSpan slidingExpiration)
        {
            ExpirationHint hint = null;

            if (DateTime.MaxValue.ToUniversalTime().Equals(absoluteExpiration) && TimeSpan.Zero.Equals(slidingExpiration))
            {
                return(null);
            }

            if (DateTime.MaxValue.ToUniversalTime().Equals(absoluteExpiration))
            {
                hint = new IdleExpiration(slidingExpiration);
            }
            else
            {
                absoluteExpiration = absoluteExpiration.ToUniversalTime();
                hint = new FixedExpiration(absoluteExpiration);
            }

            return(hint);
        }
示例#26
0
        /// <summary>
        /// We log all the operations in a transitory index when we are iterating on
        /// the main index to determine the expired items. StopLogging should be called
        /// after selection of item is completd. We apply all the logs from transitory
        /// index to the main index. A null value in transitory index against a key
        /// indicates that this item is removed during logging, so we should remove
        /// it from the main log as well.
        /// </summary>
        private void ApplyLoggs()
        {
            lock (_status_mutex)
            {
                IsInProgress = false;
                if (_indexCleared)
                {
                    //_mainIndex.Clear();
                    _mainIndex    = new HashVector();
                    _indexCleared = false;
                }

                IDictionaryEnumerator ide = _transitoryIndex.GetEnumerator();

                object         key;
                ExpirationHint expHint;
                while (ide.MoveNext())
                {
                    key     = ide.Key;
                    expHint = ide.Value as ExpirationHint;

                    ExpirationHint oldEntry = (ExpirationHint)_mainIndex[key];

                    if (expHint != null)
                    {
                        _mainIndex[key] = expHint;
                    }
                    else
                    {
                        //it means this item has been removed;
                        _mainIndex.Remove(key);
                    }

                    if (oldEntry != null)
                    {
                        _expirationManagerSize -= oldEntry.InMemorySize;
                    }
                }
            }
        }
示例#27
0
        private static ExpirationHint GetExpirationHint(PoolManager poolManager, DateTime absoluteExpiration, TimeSpan slidingExpiration)
        {
            ExpirationHint hint = null;

            if (ExpirationConstants.AbsoluteNoneExpiration.ToUniversalTime().Equals(absoluteExpiration) && ExpirationConstants.SlidingNoneExpiration.Equals(slidingExpiration))
            {
                return(null);
            }

            if (!ExpirationConstants.AbsoluteNoneExpiration.ToUniversalTime().Equals(absoluteExpiration.ToUniversalTime()))
            {
                absoluteExpiration = absoluteExpiration.ToUniversalTime();
                hint = FixedExpiration.Create(poolManager, absoluteExpiration);
            }
            else if (!ExpirationConstants.SlidingNoneExpiration.Equals(slidingExpiration))

            {
                hint = IdleExpiration.Create(poolManager, slidingExpiration);
            }

            return(hint);
        }
示例#28
0
        public void UpdateIndex(object key, CacheEntry entry)
        {
            if (key == null || entry == null || entry.ExpirationHint == null || !entry.ExpirationHint.IsIndexable)
            {
                return;
            }

            ExpirationHint hint = entry.ExpirationHint;

            lock (_status_mutex)
            {
                int addSize = hint.InMemorySize;

                if (!IsInProgress)
                {
                    if (_mainIndex.Contains(key))
                    {
                        ExpirationHint expHint = _mainIndex[key] as ExpirationHint;
                        addSize -= expHint.InMemorySize;
                    }

                    _mainIndex[key] = hint;
                }
                else
                {
                    if (_transitoryIndex.ContainsKey(key))
                    {
                        ExpirationHint expHint = _transitoryIndex[key] as ExpirationHint;
                        if (expHint != null)
                        {
                            addSize -= expHint.InMemorySize;
                        }
                    }

                    _transitoryIndex[key] = hint;
                }
                _expirationManagerSize += addSize;
            }
        }
示例#29
0
        protected sealed override void DeepCloneInternal(PoolManager poolManager, ExpirationHint clonedHint)
        {
            if (clonedHint == null)
            {
                return;
            }

            base.DeepCloneInternal(poolManager, clonedHint);

            if (clonedHint is AggregateExpirationHint clonedAggregateExpirationHint)
            {
                if (_hints != null)
                {
                    var clonedHints = new ClusteredList <ExpirationHint>(_hints.Count);

                    foreach (var hint in _hints)
                    {
                        clonedHints.Add(hint.DeepClone(poolManager));
                    }
                    clonedAggregateExpirationHint._hints = clonedHints;
                }
                clonedAggregateExpirationHint._expiringHint = _expiringHint?.DeepClone(poolManager);
            }
        }
示例#30
0
        private void LogFeatureUsage(ExpirationHint hint)
        {
            switch (hint._hintType)
            {
            case ExpirationHintType.NULL:
                break;

            case ExpirationHintType.Parent:
                break;

            case ExpirationHintType.FixedExpiration:
                FeatureUsageCollector.Instance.GetFeature(FeatureEnum.absolute_expiration, FeatureEnum.expiration).UpdateUsageTime();
                break;

            case ExpirationHintType.TTLExpiration:
                FeatureUsageCollector.Instance.GetFeature(FeatureEnum.sliding_expiration, FeatureEnum.expiration).UpdateUsageTime();
                break;

            case ExpirationHintType.TTLIdleExpiration:
                FeatureUsageCollector.Instance.GetFeature(FeatureEnum.sliding_expiration, FeatureEnum.expiration).UpdateUsageTime();
                break;

            case ExpirationHintType.FixedIdleExpiration:
                FeatureUsageCollector.Instance.GetFeature(FeatureEnum.absolute_expiration, FeatureEnum.expiration).UpdateUsageTime();
                break;

            case ExpirationHintType.IdleExpiration:
                break;

            case ExpirationHintType.AggregateExpirationHint:
                break;

            default:
                break;
            }
        }
示例#31
0
 protected override void NotifyExpiration(object sender, EventArgs e)
 {
     _expiringHint = sender as ExpirationHint;
     base.NotifyExpiration(sender, e);
 }
示例#32
0
        private CacheDependency GetNonAggregateDependencies(ExpirationHint hint)
        {
            if (hint is KeyDependency)
            {
                KeyDependency keyDep = (KeyDependency)hint;

                return(new Runtime.Dependencies.KeyDependency(keyDep.CacheKeys, new DateTime(keyDep.StartAfterTicks)));
            }
            else if (hint is FileDependency)
            {
                FileDependency fileDep = (FileDependency)hint;
                return(new Runtime.Dependencies.FileDependency(fileDep.fileNames, new DateTime(fileDep.StartAfterTicks)));
            }

            else if (hint is OleDbCacheDependency)
            {
                OleDbCacheDependency oleDbDep = (OleDbCacheDependency)hint;
                return(DBDependencyFactory.CreateOleDbCacheDependency(oleDbDep.ConnectionString, oleDbDep.DbCacheKey));
            }
            else if (hint is Sql7CacheDependency)
            {
                Sql7CacheDependency sql7Dep = (Sql7CacheDependency)hint;
                return(DBDependencyFactory.CreateSqlCacheDependency(sql7Dep.ConnectionString, sql7Dep.DbCacheKey));
            }

            else if (hint is OracleCacheDependency)
            {
                OracleCacheDependency oracleDep = (OracleCacheDependency)hint;

                Dictionary <string, OracleCmdParams> parameters = new Dictionary <string, OracleCmdParams>();
                IDictionaryEnumerator enu = oracleDep.CommandParams.GetEnumerator();
                while (enu.MoveNext())
                {
                    string key = enu.Key.ToString();
                    OracleCommandParams cmdParam = (OracleCommandParams)enu.Value;

                    OracleCmdParams commandParam = new OracleCmdParams();

                    commandParam.Direction = (OracleParameterDirection)cmdParam.Direction;
                    commandParam.Type      = (OracleCmdParamsType)cmdParam.Type;
                    commandParam.Value     = cmdParam.Value;

                    parameters.Add(key, commandParam);
                }

                Runtime.Dependencies.OracleCacheDependency oraDep = new Runtime.Dependencies.OracleCacheDependency(oracleDep.ConnectionString,
                                                                                                                   oracleDep.QueryString,
                                                                                                                   (OracleCommandType)oracleDep.CommandType,
                                                                                                                   parameters);
                return(oraDep);
            }

            else if (hint is SqlYukonCacheDependency)
            {
                SqlYukonCacheDependency yukonDep = (SqlYukonCacheDependency)hint;

                Dictionary <string, Runtime.Dependencies.SqlCmdParams> parameters = new Dictionary <string, Runtime.Dependencies.SqlCmdParams>();
                IDictionaryEnumerator enu = yukonDep.CommandParams.GetEnumerator();

                while (enu.MoveNext())
                {
                    string       key   = enu.Key.ToString();
                    SqlCmdParams param = (SqlCmdParams)enu.Value;
                    Runtime.Dependencies.SqlCmdParams yukonCmdParam = new Runtime.Dependencies.SqlCmdParams();

                    yukonCmdParam.SqlParamDir             = param.Direction;
                    yukonCmdParam.Type                    = (CmdParamsType)param.DbType;
                    yukonCmdParam.IsNullable              = param.IsNullable;
                    yukonCmdParam.LocaleID                = param.LocaleID;
                    yukonCmdParam.Offset                  = param.Offset;
                    yukonCmdParam.Precision               = param.Precision;
                    yukonCmdParam.Scale                   = param.Scale;
                    yukonCmdParam.Size                    = param.ParamSize;
                    yukonCmdParam.SourceColumn            = param.SourceColumn;
                    yukonCmdParam.SourceColumnNullMapping = param.SourceColumnNullMapping;
                    yukonCmdParam.SqlValue                = param.SqlValue;
                    yukonCmdParam.SourceVersion           = (SqlDataRowVersion)(int)param.SrcVersion;
                    yukonCmdParam.TypeName                = param.TypeName;
                    yukonCmdParam.UdtTypeName             = param.UdtName;
                    yukonCmdParam.Value                   = param.Value;

                    parameters.Add(key, yukonCmdParam);
                }

                Runtime.Dependencies.SqlCacheDependency sqlDep = new Runtime.Dependencies.SqlCacheDependency(yukonDep.ConnectionString,
                                                                                                             yukonDep.QueryString,
                                                                                                             (SqlCommandType)yukonDep.CommandType,
                                                                                                             parameters);
                return(sqlDep);
            }
            if (hint is NosDBCacheDependency)
            {
                NosDBCacheDependency nosDbDep = (NosDBCacheDependency)hint;

                Dictionary <string, object> parameters = new Dictionary <string, object>();
                IDictionaryEnumerator       enu        = nosDbDep.CommandParams.GetEnumerator();
                while (enu.MoveNext())
                {
                    string key = enu.Key.ToString();
                    parameters.Add(key, enu.Value);
                }
                NosDBDependency oraDep = new NosDBDependency(nosDbDep.ConnectionString, nosDbDep.QueryString, parameters, nosDbDep.Timeout);
                return(oraDep);
            }
            return(null);
        }
示例#33
0
        /// <summary>
        /// Overload of Insert operation for bulk inserts. Uses additional EvictionHint and ExpirationHint parameters.
        /// </summary>
        public IDictionary Insert(object[] keys, object[] values, ExpirationHint expiryHint, EvictionHint evictionHint, OperationContext operationContext)
        {

            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];

            for (int i = 0; i < values.Length; i++)
            {
                object key = keys[i];
                object value = values[i];


                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 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 null; 

                ce[i] = new CacheEntry(value, expiryHint, evictionHint);

            }
            /// update the counters for various statistics
            try
            {
                return Insert(keys, ce, operationContext);
            }
            catch (Exception inner)
            {
                throw;
            }
        }
示例#34
0
 public virtual bool Add(object key, ExpirationHint eh, OperationContext operationContext)
 {
     return false;
 }
示例#35
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;
            }
        }
示例#36
0
        public override bool Add(object key, ExpirationHint eh, OperationContext operationContext)
        {
            bool depAdded = false;
            
            if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("CacheSyncWrp.Add_3", "enter");

            Sync.AcquireWriterLock(Timeout.Infinite);
            try
            {
                depAdded = Internal.Add(key, eh, operationContext);
                
#if !CLIENT
                if(depAdded && _context.CacheImpl.RequiresReplication)
                {
                    _context.CacheImpl.EnqueueForReplication(null, (int)ClusterCacheBase.OpCodes.AddHint, new object[] { key, eh, operationContext });
                }
#endif
            }
            finally
            {
                Sync.ReleaseWriterLock();
                if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("CacheSyncWrp.Add_3", "exit");

            }
            return depAdded;
        }
 /// <summary>
 /// Add the ExpirationHint to the cluster. 
 /// </summary>
 /// <param name="key">key of the entry.</param>
 /// <returns>cache entry.</returns>
 /// <remarks>
 /// This method invokes <see cref="handleAddHint"/> on every server-node in the cluster. If the operation
 /// fails on any one node the whole operation is considered to have failed and is rolled-back.
 /// </remarks>
 private bool Clustered_Add(object key, ExpirationHint eh, OperationContext operationContext)
 {
     return Clustered_Add(Cluster.Servers, key, eh, operationContext);
 }
示例#38
0
 internal virtual bool AddInternal(object key, ExpirationHint eh, OperationContext operationContext)
 {
     return false;
 }
示例#39
0
        public sealed override bool Add(object key, ExpirationHint eh, OperationContext operationContext)
        {
            if (eh == null)
                return false;
            CacheEntry entry = GetInternal(key, false, operationContext);
            bool result = AddInternal(key, eh, operationContext);
            if (result)
            {
                eh.CacheKey = (string)key;
                if (!eh.Reset(_context))
                {
                    RemoveInternal(key, eh);
                    throw new OperationFailedException("Unable to initialize expiration hint");
                }
                
                _context.ExpiryMgr.UpdateIndex(key, entry.ExpirationHint);
            }

            if (_context.PerfStatsColl != null)
            {
                _context.PerfStatsColl.SetCacheSize(Size);
            }
            return result;
        }
示例#40
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <param name="eh"></param>
        /// <returns></returns>
        internal override bool AddInternal(object key, ExpirationHint eh, OperationContext operationContext)
        {
            if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("LocalCache.Add_2", "");

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

            CacheEntry e = (CacheEntry)_cacheStore.Get(key);
            if (e == null) return false;

            //We only allow either idle expiration or Fixed expiration both cannot be set at the same time
            if ((e.ExpirationHint is IdleExpiration && eh is FixedExpiration)
                || (e.ExpirationHint is FixedExpiration && eh is IdleExpiration))
            {
                return false;
            }

            e.ExpirationHint = eh;
            _cacheStore.Insert(key, e, true);
            e.LastModifiedTime = System.DateTime.Now;


            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 true;
        }
示例#41
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <param name="eh"></param>
        /// <returns></returns>
        internal override bool RemoveInternal(object key, ExpirationHint eh)
        {
            if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("LocalCache.Remove", "");

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

            CacheEntry e = (CacheEntry)_cacheStore.Get(key);
            if (e == null || e.ExpirationHint == null)
            {
                return false;
            }
            else if (e.ExpirationHint.Equals(eh))
            {
                e.ExpirationHint = null;
            }

            //SAL: Our store may not be an in memory store
            
            if (_notifyCacheFull)
            {
                _notifyCacheFull = false;
            }
            _cacheStore.Insert(key, e, true);
            e.LastModifiedTime = System.DateTime.Now;

            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 true;
        }
示例#42
0
 public void Deserialize(CompactReader reader)
 {
     _key = reader.ReadObject();
     _value = reader.ReadObject();
     _expiration = reader.ReadInt64();
     _dependency = ExpirationHint.ReadExpHint(reader);
     _options = reader.ReadByte();
     _itemRemovedCallback = reader.ReadObject();
     _queryInfo = (Hashtable)reader.ReadObject();
 }
示例#43
0
        public void Reset()
        {
            _key = null;
            _value = null;
            _dependency = null;
            _expiration = 0;
            _options = 0;
            _itemRemovedCallback = null;
            _queryInfo = null;

        }
示例#44
0
 public void ResetVariant(ExpirationHint hint)
 {
     lock (this)
     {
         hint.ResetVariant(_context);
     }
 }
示例#45
0
 /// <summary>
 /// Overload of Insert operation for bulk inserts. Uses an additional ExpirationHint parameter to be used 
 /// for Item Expiration Feature.
 /// </summary>
 public IDictionary Insert(object[] keys, object[] values, ExpirationHint expiryHint, OperationContext operationContext)
 {
     return Insert(keys, values, expiryHint, null, operationContext);
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="key"></param>
 /// <param name="eh"></param>
 /// <param name="operationContext"></param>
 /// <returns></returns>
 private bool Local_Add(object key, ExpirationHint eh, OperationContext operationContext)
 {
     bool retVal = false;
     if (_internalCache != null)
         retVal = _internalCache.Add(key, eh, operationContext);
     return retVal;
 }
示例#47
0
        /// <summary>
        /// Insert array of CompactCacheEntry to cache, these may be serialized
        /// </summary>
        /// <param name="entries"></param>
        public IDictionary InsertEntries(object[] entries, OperationContext operationContext)
        {
            // check if cache is running.
            if (!IsRunning) return null;

            string[] keys = new string[entries.Length];
            object[] values = new object[entries.Length];

            CallbackEntry[] callbackEnteries = new CallbackEntry[entries.Length]; 
            ExpirationHint[] exp = new ExpirationHint[entries.Length];
            EvictionHint[] evc = new EvictionHint[entries.Length];
            BitSet[] flags = new BitSet[entries.Length];
            Hashtable[] queryInfo = new Hashtable[entries.Length];
            CallbackEntry cbEntry = null;

            for (int i = 0; i < entries.Length; i++)
            {
                CompactCacheEntry cce = (CompactCacheEntry)SerializationUtil.CompactDeserialize(entries[i], _context.SerializationContext);
                keys[i] = cce.Key as string;
                CacheEntry ce = MakeCacheEntry(cce);
                if (ce != null)
                {
                    if (ce.Value is CallbackEntry)
                        cbEntry = ce.Value as CallbackEntry;
                    else
                        cbEntry = null;

                    callbackEnteries[i] = cbEntry;

                    object value = ce.Value as CallbackEntry;
                    values[i] = value == null ? ce.Value : ((CallbackEntry)ce.Value).Value;

                    exp[i] = ce.ExpirationHint;
                    evc[i] = ce.EvictionHint;
                    queryInfo[i] = ce.QueryInfo;
                    flags[i] = ce.Flag;
                }
            }

            IDictionary items= Insert(keys, values, callbackEnteries, exp, evc, queryInfo, flags, operationContext);
           
            return items;
        }
示例#48
0
 public ExpiryIndexEntry(ExpirationHint hint)
 {
     _hint = hint;
 }
示例#49
0
 /// <summary>
 /// Add the ExpirationHint to a specfied node in the cluster. 
 /// </summary>
 /// <param name="key">key of the entry.</param>
 /// <returns>cache entry.</returns>
 /// <remarks>
 /// This method either invokes <see cref="handleAdd"/> on every server-node in the cluster.
 /// </remarks>
 protected bool Clustered_Add(Address dest, object key, ExpirationHint eh, OperationContext operationContext)
 {
     bool retVal = false;
     try
     {
         Function func = new Function((int)OpCodes.AddHint, new object[] { key, eh, operationContext });
         object result = Cluster.SendMessage(dest, func, GroupRequest.GET_FIRST);
         if (result == null)
         {
             return retVal;
         }
         retVal = (bool)result; 
     }
     catch (StateTransferException e)
     {
         throw;
     }
     catch (CacheException e)
     {
         throw;
     }
     catch (Exception e)
     {
         throw new GeneralFailureException(e.Message, e);
     }
     return retVal;
 }
示例#50
0
 /// <summary>
 /// Initialize the new hint. if no new hint is specified then dispose the old hint.
 /// </summary>
 /// <param name="oldHint"></param>
 /// <param name="newHint"></param>
 public void ResetHint(ExpirationHint oldHint, ExpirationHint newHint)
 {
     lock (this)
     {
         if (newHint != null)
         {
             if (oldHint != null) ((IDisposable)oldHint).Dispose(); //dispose only if newHint is not null
             newHint.Reset(_context);
         }
     }
 }
示例#51
0
 /// <summary>
 /// Remove an ExpirationHint against the given key
 /// Key must already exists in the cache
 /// </summary>
 /// <param name="key"></param>
 /// <param name="eh"></param>
 /// <returns></returns>
 internal virtual bool RemoveInternal(object key, ExpirationHint eh)
 {
     return false;
 }
示例#52
0
        public void UpdateIndex(object key, ExpirationHint hint)
        {
            if (key == null || hint == null) return;

            lock (_status_mutex)
            {
                int addSize = 0;
                int removeSize = 0;

                if (!IsInProgress)
                {
                    if (!_mainIndex.Contains(key))
                    {
                        ExpiryIndexEntry entry = new ExpiryIndexEntry(hint);
                        _mainIndex[key] = entry;

                        addSize = entry.InMemorySize;

                        if (_mainIndex.Count > _mainIndexMaxCount)
                            _mainIndexMaxCount = _mainIndex.Count;                   
                    }
                    else
                    {
                        ExpiryIndexEntry expEntry = _mainIndex[key] as ExpiryIndexEntry;
                        if (expEntry != null)
                        {
                            removeSize = expEntry.InMemorySize;
                            expEntry.Hint = hint;
                            addSize = expEntry.InMemorySize;
                        }
                    }
                }
                else
                {
                    if (_transitoryIndex[key] == null)
                    {
                        ExpiryIndexEntry entry = new ExpiryIndexEntry(hint);
                        _transitoryIndex[key] = entry;
                        addSize = entry.InMemorySize;

                        if (_transitoryIndex.Count > _transitoryIndexMaxCount)
                            _transitoryIndexMaxCount = _transitoryIndex.Count;
                    }
                    else
                    {
                        ExpiryIndexEntry expEntry = _transitoryIndex[key] as ExpiryIndexEntry;
                        if (expEntry != null)
                        {
                            removeSize = expEntry.InMemorySize;
                            expEntry.Hint = hint;
                            addSize = expEntry.InMemorySize;
                        }
                    }
                }
                _expirationManagerSize -= removeSize;
                _expirationManagerSize += addSize;
            }
        }
示例#53
0
        /// <summary>
        /// Add the object to the cluster. Does load balancing as well.
        /// </summary>
        /// <param name="key">key of the entry.</param>
        /// <returns>cache entry.</returns>
        /// <remarks>
        /// This method either invokes <see cref="handleAdd"/> on one of the server nodes in the cluster, 
        /// or invokes <see cref="Local_Add"/> locally.
        /// </remarks>
        protected bool Clustered_Add(ArrayList dests, object key, ExpirationHint eh, OperationContext operationContext)
        {
            bool result = false;
            try
            {
                /// Ask every server to add the object, except myself.
                Function func = new Function((int)OpCodes.AddHint, new object[] { key, eh, operationContext }, false, key);
                RspList results = Cluster.BroadcastToMultiple(dests,
                    func,
                    GroupRequest.GET_ALL, _asyncOperation);

                ClusterHelper.ValidateResponses(results, typeof(bool), Name);

                /// Check if the operation failed on any node.
                result = ClusterHelper.FindAtomicAddHintReplicated(results);
            }
            catch (CacheException e)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new GeneralFailureException(e.Message, e);
            }
            return result;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <param name="eh"></param>
        /// <returns></returns>
        public override bool Add(object key, ExpirationHint eh, OperationContext operationContext)
        {
            bool result = false;
            if (ServerMonitor.MonitorActivity) ServerMonitor.LogClientActivity("PrtCache.Add_3", "");

            /// Wait until the object enters the running status
            _statusLatch.WaitForAny(NodeStatus.Running);

            if (_internalCache == null) throw new InvalidOperationException();


            bool suspectedErrorOccured = false;
            Address targetNode = null;

            while (true)
            {
                try
                {
                    targetNode = GetNextNode(key as string);
                    if (targetNode != null)
                    {
                        if (targetNode.compare(LocalAddress) == 0)
                        {
                            result = Local_Add(key, eh, operationContext);
                            break;
                        }
                        else
                        {
                            result = Clustered_Add(targetNode, key, eh, operationContext);
                            break;
                        }
                    }
                    result = false;
                    break;
                }
                catch (Alachisoft.NGroups.SuspectedException se)
                {
                    suspectedErrorOccured = true;
                    //we redo the operation
                    if (NCacheLog.IsInfoEnabled) NCacheLog.Info("PartitionedServerCache.Add", targetNode + " left while addition. Error: " + se.ToString());
                    continue;
                }
                catch (Runtime.Exceptions.TimeoutException te)
                {
                    if (NCacheLog.IsInfoEnabled) NCacheLog.Info("PartitionedServerCache.Add", targetNode + " operation timed out. Error: " + te.ToString());
                    if (suspectedErrorOccured)
                    {
                        suspectedErrorOccured = false;
                        continue;
                    }
                    else
                    {
                        throw new GeneralFailureException(te.Message, te);
                    }
                }
                catch (Alachisoft.NCache.Caching.Exceptions.StateTransferException se)
                {
                    _distributionMgr.Wait(key);
                }

            }

            return result;
        }
示例#55
0
        /// <summary>
        /// Called by the scheduler to remove the items that has expired
        /// </summary>
        public bool Expire()
        {
            //indicates whether some items expired during this interval or not...
            bool expired = false;

            //if user has updated the file then the new values will be reloaded.
            _sleepInterval    = ServiceConfiguration.ExpirationBulkRemoveDelay;
            _removeThreshhold = ServiceConfiguration.ExpirationBulkRemoveSize;

            CacheBase cacheInst = _context.CacheImpl;
            CacheBase cache     = _context.CacheInternal;
            Cache     rootCache = _context.CacheRoot;

            if (cache == null)
            {
                throw new InvalidOperationException("No cache instance defined");
            }

            bool allowExpire = AllowClusteredExpiry;

            //in case of replication and por, only the coordinator/sub-coordinator is responsible to expire the items.
            if (!allowExpire)
            {
                return(false);
            }
            ClusteredArrayList selectedKeys = new ClusteredArrayList();
            int        oldItemsCount        = 0;
            HashVector oldeItems            = null;

            try
            {
                StartLogging();

                DateTime startTime   = DateTime.Now;
                int      currentTime = AppUtil.DiffSeconds(startTime);
                int      cleanSize   = (int)Math.Ceiling(cache.Count * _cleanRatio);

                //set the flag that we are going to expire the items.

                if (_cacheLastAccessLoggingIntervalPassed >= _cacheLastAccessLoggingInterval)
                {
                    _cacheLastAccessLoggingInterval     = CacheLastAccessLoggingInterval;
                    _cacheLastAccessCountEnabled        = IsCacheLastAccessCountEnabled;
                    _cacheLastAccessCountLoggingEnabled = IsCacheLastAccessLoggingEnabled;
                    _cacheLastAccessInterval            = CacheLastAccessCountInterval;
                }
                else
                {
                    _cacheLastAccessLoggingIntervalPassed++;
                }


                if (_cacheLastAccessCountEnabled && _cacheLastAccessCountLoggingEnabled)
                {
                    if (_cacheLastAccessLoggingIntervalPassed >= _cacheLastAccessLoggingInterval)
                    {
                        _cacheLastAccessLoggingIntervalPassed = 0;
                        oldeItems = new HashVector();
                    }
                }
                lock (_mainIndex.SyncRoot)
                {
                    IDictionaryEnumerator em = _mainIndex.GetEnumerator();

                    if (em != null)
                    {
                        while (em.MoveNext())
                        {
                            ExpirationHint hint = em.Value as ExpirationHint;
                            if (hint != null && _cacheLastAccessCountEnabled && hint is IdleExpiration)
                            {
                                IdleExpiration slidingExpHint = hint as IdleExpiration;
                                TimeSpan       diff           = AppUtil.GetDateTime(AppUtil.DiffSeconds(DateTime.Now)) - AppUtil.GetDateTime(slidingExpHint.LastAccessTime);
                                if (diff.TotalMinutes >= _cacheLastAccessInterval)
                                {
                                    oldItemsCount++;
                                    if (oldeItems != null)
                                    {
                                        oldeItems.Add(em.Key, null);
                                    }
                                }
                            }
                            if (hint == null || hint.SortKey.CompareTo(currentTime) >= 0)
                            {
                                continue;
                            }

                            if (hint.DetermineExpiration(_context))
                            {
                                selectedKeys.Add(em.Key);
                                if (cleanSize > 0 && selectedKeys.Count == cleanSize)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
                if (NCacheLog.IsInfoEnabled)
                {
                    NCacheLog.Info("ExpirationManager.Expire()", String.Format("Expiry time for {0}/{1} Items: " + (DateTime.UtcNow - startTime), selectedKeys.Count, /*_expiryIndex.KeyCount*/ cache.Count));
                }
            }
            catch (Exception e)
            {
                NCacheLog.Error("ExpirationManager.Expire(bool)", "LocalCache(Expire): " + e.ToString());
            }
            finally
            {
                _context.PerfStatsColl.IncrementCacheLastAccessCountStats(oldItemsCount);

                ApplyLoggs();
                ClusteredArrayList dependentItems = new ClusteredArrayList();
                DateTime           startTime      = DateTime.Now;

                HashVector expiredItemTable = new HashVector();

                expiredItemTable.Add(ItemRemoveReason.Expired, selectedKeys);//Time based expiration
                try
                {
                    IDictionaryEnumerator ide = expiredItemTable.GetEnumerator();

                    while (ide.MoveNext())
                    {
                        selectedKeys = ide.Value as ClusteredArrayList;
                        ItemRemoveReason removedReason = (ItemRemoveReason)ide.Key;

                        if (selectedKeys.Count > 0)
                        {
                            //new architectural changes begins from here.

                            ClusteredArrayList keysTobeRemoved = new ClusteredArrayList();

                            for (int i = 0; i < selectedKeys.Count && !_cacheCleared; i++)
                            {
                                keysTobeRemoved.Add(selectedKeys[i]);
                                if (keysTobeRemoved.Count % _removeThreshhold == 0)
                                {
                                    try
                                    {
                                        if (this.IsDisposed)
                                        {
                                            break;
                                        }

                                        OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation);
                                        object[][]       keysExposed      = keysTobeRemoved.ToInternalArray();
                                        foreach (object[] collection in keysExposed)
                                        {
                                            cache.RemoveSync(collection, removedReason, false, operationContext);
                                        }
                                        //set the flag that item has expired from cache...
                                        expired = true;

                                        if (_context.PerfStatsColl != null)
                                        {
                                            _context.PerfStatsColl.IncrementExpiryPerSecStatsBy(keysTobeRemoved.Count);
                                        }
                                    }
                                    catch (Exception e)
                                    {
                                        NCacheLog.Error("ExpiryManager.Expire", "an error occurred while removing expired items. Error " + e.ToString());
                                    }
                                    keysTobeRemoved.Clear();
                                    //we stop the activity of the current thread so that normal user operation is not affected.
                                    Thread.Sleep(_sleepInterval);
                                }
                            }

                            if (!this.IsDisposed && keysTobeRemoved.Count > 0)
                            {
                                try
                                {
                                    OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation);
                                    object[][]       keysExposed      = keysTobeRemoved.ToInternalArray();
                                    foreach (object[] keyCollection in keysExposed)
                                    {
                                        cache.RemoveSync(keyCollection, removedReason, false, operationContext);
                                    }
                                    //set the flag that item has expired from cache...
                                    expired = true;
                                    if (_context.PerfStatsColl != null)
                                    {
                                        _context.PerfStatsColl.IncrementExpiryPerSecStatsBy(keysTobeRemoved.Count);
                                    }
                                }
                                catch (Exception e)
                                {
                                    NCacheLog.Error("ExpiryManager.Expire", "an error occurred while removing expired items. Error " + e.ToString());
                                }
                            }
                        }
                    }
                }
                finally
                {
                    _transitoryIndex.Clear();
                    lock (this)
                    {
                        _cacheCleared = false;
                    }

                    if (oldeItems != null)
                    {
                        StringBuilder         sb  = new StringBuilder();
                        IDictionaryEnumerator ide = oldeItems.GetEnumerator();
                        int count = 1;
                        while (ide.MoveNext())
                        {
                            sb.Append(ide.Key + ", ");

                            if (count % 10 == 0)
                            {
                                sb.Append("\r\n");
                                count = 1;
                            }
                            else
                            {
                                count++;
                            }
                        }

                        NCacheLog.Info(sb.ToString().Trim());
                    }
                }
            }
            return(expired);
        }
示例#56
0
        internal override bool AddInternal(object key, ExpirationHint eh, OperationContext operationContext)
        {
            if (_primary == null || _secondary == null)
                throw new InvalidOperationException();

            // If the primary has it then we are bound to update that item
            if (_primary.ContainsInternal(key))
            {
                return _primary.AddInternal(key, eh, operationContext);
            }

            // If the secondary has it then we are bound to update that item
            if (_secondary.Contains(key, operationContext))
            {
                return _secondary.AddInternal(key, eh, operationContext);
            }

            return false;
        }
示例#57
0
 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;
     }
 }
        /// <summary>
        /// Add ExpirationHint against the given key
        /// </summary>
        /// <param name="key"></param>
        /// <param name="eh"></param>
        /// <returns></returns>
        public override bool Add(object key, ExpirationHint eh, OperationContext operationContext)
        {
            /// Wait until the object enters any running status
            _statusLatch.WaitForAny(NodeStatus.Initializing | NodeStatus.Running);

            if (_internalCache == null) throw new InvalidOperationException();

            if (Context.NCacheLog.IsInfoEnabled) Context.NCacheLog.Info("Replicated.Add()", "Key = " + key);

            if (Local_Contains(key, operationContext) == false) return false;
            bool result;
             try
            {
                if (Cluster.Servers.Count > 1)
                {
                    // Try to add to the local node and the cluster.
                    result = Clustered_Add(key, eh, operationContext);
                }
                else
                    result = Local_Add(key, eh, operationContext);
            }
            catch (Exception e)
            {
                throw e;
            }

            return result;
        }
示例#59
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;
     }
 }
 /// <summary>
 /// Add the ExpirationHint against the given key
 /// </summary>
 /// <param name="key"></param>
 /// <param name="hint"></param>
 /// <returns></returns>
 private bool Local_Add(object key, ExpirationHint hint, OperationContext operationContext)
 {
     bool retVal = false;
     if (_internalCache != null)
     {
         try
         {
             retVal = _internalCache.Add(key, hint, operationContext);
         }
         catch (Exception e)
         {
             throw e;
         }
                    
     }
     return retVal;
 }