Пример #1
0
        private bool _SetTTL(string key, TimeSpan slidingExpiration, TimeSpan absoluteExpiration, RedisDal dal)
        {
            bool result = false;

            if (slidingExpiration != Utility.NO_EXPIRATION || absoluteExpiration != Utility.NO_EXPIRATION)
            {
                if (slidingExpiration != Utility.NO_EXPIRATION)
                {
                    //SET TTL
                    result = dal.SetTTL(key, slidingExpiration);
                }
                else
                {
                    if (absoluteExpiration != Utility.NO_EXPIRATION)
                    {
                        //SET TTL
                        result = dal.SetTTL(key, absoluteExpiration);
                    }
                    else
                    {
                        //ND
                    }
                }
            }
            else
            {
                //ND
            }
            return(result);
        }
Пример #2
0
        public ItemCache <T> GetItemCache <T>(string key)
        {
            if (string.IsNullOrWhiteSpace(key))
            {
                throw new ArgumentException("Parameter is invalid.", "key", null);
            }

            RedisDal dal = new RedisDal();

            StackExchange.Redis.RedisValue[] results = dal.GetListItem <T>(key);

            if (results != null && results.Length > 1)
            {
                ItemCacheInfo <T> itemCacheInfo = new ItemCacheInfo <T>();
                itemCacheInfo.Serialized_TTL  = (string)results[0];
                itemCacheInfo.Serialized_Data = results[1];
                itemCacheInfo.DeSerializeInfo();

                if (Utility.TTL_Is_Expired(itemCacheInfo.SlidingExpiration_DT, itemCacheInfo.AbsoluteExpiration_DT))
                {
                    dal.ItemDelete(key);
                    return(null);
                }
                else
                {
                    //Update SLI TTL on Redis...
                    if (itemCacheInfo.SlidingExpiration_DT != DateTime.MaxValue)
                    {
                        itemCacheInfo.UpdateSerialized_TTL();       //Update TTL

                        dal.UpdateTTL_Item(key, itemCacheInfo.Serialized_TTL);
                        dal.SetTTL(key, itemCacheInfo.SlidingExpiration_TS);
                    }

                    //Prepare ItemCache Result...
                    ItemCache <T> result = new ItemCache <T>();
                    result.SlidingExpiration  = itemCacheInfo.SlidingExpiration_TS;
                    result.AbsoluteExpiration = itemCacheInfo.AbsoluteExpiration_TS;
                    result.Key   = key;
                    result.Value = itemCacheInfo.Data;
                    return(result);
                }
            }
            else
            {
                return(null);
            }
        }