Exemple #1
0
        public static ExpirationHint GetExpirationHintObj(PoolManager poolManager, Alachisoft.NCache.Common.Protobuf.Dependency dependency, bool resyncOnExpiration, string serializationContext)
        {
            AggregateExpirationHint hints = AggregateExpirationHint.Create(poolManager);

            // POTeam
            int hintCount = hints.HintsWithoutClone.Count;

            if (hintCount == 0)
            {
                NCache.Util.MiscUtil.ReturnExpirationHintToPool(hints, poolManager);
                return(null);
            }

            if (resyncOnExpiration)
            {
                hints.SetBit(ExpirationHint.NEEDS_RESYNC);
            }

            if (hintCount == 1)
            {
                return(hints.Hints[0]);
            }

            return(hints);
        }
Exemple #2
0
        public static ExpirationHint GetExpirationHintObj(PoolManager poolManager, Alachisoft.NCache.Common.Protobuf.Dependency dependency, long absoluteExpiration, long slidingExpiration, bool resyncOnExpiration, string serializationContext)
        {
            ExpirationHint hint = null;

            //We expect Web.Cache to send in UTC DateTime, AbsoluteExpiration is dealt in UTC
            if (absoluteExpiration != Common.Util.Time.MaxUniversalTicks && absoluteExpiration != 0 && absoluteExpiration != 1 && absoluteExpiration != 2)
            {
                hint = FixedExpiration.Create(poolManager, new DateTime(absoluteExpiration, DateTimeKind.Utc));
            }

            if (slidingExpiration != 0 && slidingExpiration != 1 && slidingExpiration != 2)
            {
                hint = IdleExpiration.Create(poolManager, new TimeSpan(slidingExpiration));
            }

            ExpirationHint depHint = GetExpirationHintObj(poolManager, dependency, false, serializationContext);

            if (depHint != null)
            {
                if (hint != null)
                {
                    if (depHint is AggregateExpirationHint)
                    {
                        ((AggregateExpirationHint)depHint).Add(hint);
                        hint = depHint;
                    }
                    else
                    {
                        hint = AggregateExpirationHint.Create(poolManager, hint, depHint);
                    }
                }
                else
                {
                    hint = depHint;
                }
            }
            if (hint != null && resyncOnExpiration)
            {
                hint.SetBit(ExpirationHint.NEEDS_RESYNC);
            }
            return(hint);
        }
Exemple #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="key"></param>
        /// <param name="eh"></param>
        /// <returns></returns>
        internal override bool RemoveInternal(object key, ExpirationHint eh)
        {
            CacheEntry e = null;

            try
            {
                if (ServerMonitor.MonitorActivity)
                {
                    ServerMonitor.LogClientActivity("LocalCache.Remove", "");
                }

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

                e = (CacheEntry)_cacheStore.Get(key);
                if (e == null || e.ExpirationHint == null)
                {
                    return(false);
                }
                else
                {
                    e.MarkInUse(NCModulesConstants.LocalCache);

                    if (e.ExpirationHint is AggregateExpirationHint)
                    {
                        AggregateExpirationHint AggHint      = AggregateExpirationHint.Create(Context.StorePoolManager);
                        AggregateExpirationHint entryExpHint = (AggregateExpirationHint)e.ExpirationHint;

                        foreach (ExpirationHint exp in entryExpHint)
                        {
                            if (!exp.Equals(eh))
                            {
                                AggHint.Add(exp);
                            }
                            else
                            {
                                MiscUtil.ReturnExpirationHintToPool(exp, Context.StorePoolManager);
                            }
                        }
                        e.ExpirationHint = AggHint;
                    }
                    else if (e.ExpirationHint.Equals(eh))
                    {
                        MiscUtil.ReturnExpirationHintToPool(e.ExpirationHint, Context.StorePoolManager);
                        e.ExpirationHint = null;
                    }
                }

                // 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);
            }
            finally
            {
                if (e != null)
                {
                    e.MarkFree(NCModulesConstants.LocalCache);
                }
            }
        }
Exemple #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="key"></param>
        /// <param name="eh"></param>
        /// <returns></returns>
        internal override bool AddInternal(object key, ExpirationHint eh, OperationContext operationContext)
        {
            CacheEntry e = null;

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

                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);
                }

                if (e.ExpirationHint == null)
                {
                    e.ExpirationHint = eh;
                }
                else
                {
                    if (e.ExpirationHint is AggregateExpirationHint)
                    {
                        ((AggregateExpirationHint)e.ExpirationHint).Add(eh);
                    }
                    else
                    {
                        AggregateExpirationHint aeh = AggregateExpirationHint.Create(Context.StorePoolManager);
                        aeh.Add(e.ExpirationHint);
                        aeh.Add(eh);
                        e.ExpirationHint = aeh;
                    }
                }
                e.MarkFree(NCModulesConstants.Global);
                e.MarkInUse(NCModulesConstants.LocalCache);

                //Our store may not be an in memory store

                _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);
            }
            finally
            {
                if (e != null)
                {
                    e.MarkFree(NCModulesConstants.LocalCache);
                }
            }
        }