示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ticks"></param>
        /// <param name="isSliding"></param>
        /// <returns></returns>
        ///
        public static ExpirationHint MakeExpirationHint(PoolManager poolManger, long ticks, bool isAbsolute)
        {
            if (ticks == 0)
            {
                return(null);
            }
            IdleExpiration idleExpiration = null;

            if (!isAbsolute)
            {
                TimeSpan slidingExpiration = new TimeSpan(ticks);


                if (slidingExpiration.CompareTo(TimeSpan.Zero) < 0)
                {
                    throw new ArgumentOutOfRangeException("slidingExpiration");
                }

                if (slidingExpiration.CompareTo(DateTime.Now.AddYears(1) - DateTime.Now) >= 0)
                {
                    throw new ArgumentOutOfRangeException("slidingExpiration");
                }


                idleExpiration = IdleExpiration.Create(poolManger, slidingExpiration);
                return(idleExpiration);
            }
            else
            {
                DateTime absoluteExpiration = new DateTime(ticks, DateTimeKind.Utc);
                return(FixedExpiration.Create(poolManger, absoluteExpiration));
            }
        }
示例#2
0
        public static ExpirationHint GetExpirationHintObj(long absoluteExpiration, long slidingExpiration, string serializationContext)
        {
            ExpirationHint hint = null;

            //We expect Web.Cache to send in UTC DateTime, AbsoluteExpiration is dealt in UTC
            if (absoluteExpiration != 0 && absoluteExpiration != DateTime.MaxValue.ToUniversalTime().Ticks)
            {
                hint = new FixedExpiration(new DateTime(absoluteExpiration, DateTimeKind.Utc));
            }
            if (slidingExpiration != 0)
            {
                hint = new IdleExpiration(new TimeSpan(slidingExpiration));
            }


            return(hint);
        }
示例#3
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);
        }
示例#4
0
        public static ExpirationHint GetExpirationHintObj(Alachisoft.NCache.Config.Dom.ExpirationPolicy policy, Alachisoft.NCache.Common.Protobuf.Dependency dependency, long absoluteExpiration, long slidingExpiration, bool resyncOnExpiration, string serializationContext)
        {
            ConvHelper.ValidateExpiration(policy);
            ExpirationHint hint  = null;
            const long     TICKS = 10000000;

            if ((absoluteExpiration == 1 || absoluteExpiration == 2) || (slidingExpiration == 1 || slidingExpiration == 2))
            {
                if (policy.SlidingExpiration.LongerEnabled || policy.SlidingExpiration.DefaultEnabled || policy.AbsoluteExpiration.LongerEnabled || policy.AbsoluteExpiration.DefaultEnabled)
                {
                    #region In case user provides sliding expiration as an enum

                    if (absoluteExpiration == 0)
                    {
                        if (policy.SlidingExpiration.LongerEnabled && slidingExpiration == 2)
                        {
                            hint = new IdleExpiration(new TimeSpan(policy.SlidingExpiration.Longer * TICKS));
                        }
                        else if (policy.SlidingExpiration.DefaultEnabled && slidingExpiration == 1)
                        {
                            hint = new IdleExpiration(new TimeSpan(policy.SlidingExpiration.Default * TICKS));
                        }
                    }
                    #endregion

                    #region In case user provides absolute expiration as an enum

                    if (slidingExpiration == 0)
                    {
                        if (policy.AbsoluteExpiration.LongerEnabled && absoluteExpiration == 2)// If not enabled try to check if Longer Expiration is enabled
                        {
                            hint = new FixedExpiration(DateTime.Now.AddSeconds(policy.AbsoluteExpiration.Longer).ToUniversalTime());
                        }
                        else if (absoluteExpiration == 1 && policy.AbsoluteExpiration.DefaultEnabled)// check if Longer is enabled in config
                        {
                            hint = new FixedExpiration(DateTime.Now.AddSeconds(policy.AbsoluteExpiration.Default).ToUniversalTime());
                        }
                    }
                    #endregion
                }
                else
                {
                    absoluteExpiration = 0;// If user provides custom expiration but it is NOT enabled then item will stay in cache, forever.
                }
            }

            //We expect Web.Cache to send in UTC DateTime, AbsoluteExpiration is dealt in UTC
            if (absoluteExpiration != 0 && absoluteExpiration != 1 && absoluteExpiration != 2 && absoluteExpiration != DateTime.MaxValue.ToUniversalTime().Ticks)
            {
                hint = new FixedExpiration(new DateTime(absoluteExpiration, DateTimeKind.Utc));
            }
            if (slidingExpiration != 0 && slidingExpiration != 1 && slidingExpiration != 2)
            {
                hint = new IdleExpiration(new TimeSpan(slidingExpiration));
            }
            ExpirationHint depHint = GetExpirationHintObj(dependency, false, serializationContext);

            if (depHint != null)
            {
                if (hint != null)
                {
                    if (depHint is AggregateExpirationHint)
                    {
                        ((AggregateExpirationHint)depHint).Add(hint);
                        hint = depHint;
                    }
                    else
                    {
                        hint = new AggregateExpirationHint(hint, depHint);
                    }
                }
                else
                {
                    hint = depHint;
                }
            }


            if (hint != null && resyncOnExpiration)
            {
                hint.SetBit(ExpirationHint.NEEDS_RESYNC);
            }

            return(hint);
        }