Пример #1
0
 /// <summary>
 /// Lấy thời gian cập nhật cache lần cuối
 /// </summary>
 /// <param name="parentCatId"></param>
 /// <param name="key"></param>
 /// <returns>Nếu chưa có cache thì trả về DateTime.MinValue</returns>
 public static DateTime GetLastUpdateCache(int parentCatId, string key)
 {
     if (IsAllowDistributedCached)
     {
         string lastUpdateKey = string.Format(Constants.CACHE_NAME_LAST_UPDATE, key);
         try
         {
             object lastUpdate = DistCached.GetInstance(parentCatId).Get(lastUpdateKey);
             if (null != lastUpdate)
             {
                 return(Convert.ToDateTime(lastUpdate));
             }
             else
             {
                 return(DateTime.MinValue);
             }
         }
         catch
         {
             return(DateTime.MinValue);
         }
     }
     else
     {
         return(DateTime.MinValue);
     }
 }
Пример #2
0
 public static void RemoveAll()
 {
     if (IsAllowDistributedCached)
     {
         DistCached.GetInstance(ParentCategoryId).RemoveAll();
     }
 }
Пример #3
0
 public static void RemoveAll(int parentCatId)
 {
     if (IsAllowDistributedCached)
     {
         DistCached.GetInstance(parentCatId).RemoveAll();
     }
 }
Пример #4
0
 public static void Remove(string key)
 {
     if (IsAllowDistributedCached)
     {
         string lastUpdateKey = string.Format(Constants.CACHE_NAME_LAST_UPDATE, key);
         DistCached.GetInstance(ParentCategoryId).Remove(key);
         DistCached.GetInstance(ParentCategoryId).Remove(lastUpdateKey);
     }
 }
Пример #5
0
 public static void Remove(int parentCatId, string key)
 {
     if (IsAllowDistributedCached)
     {
         string lastUpdateKey = string.Format(Constants.CACHE_NAME_LAST_UPDATE, key);
         DistCached.GetInstance(parentCatId).Remove(key);
         DistCached.GetInstance(parentCatId).Add(lastUpdateKey, DateTime.Now.ToString(), 864000 * 1000);
     }
 }
Пример #6
0
 public static void Remove_MemCache(string key)
 {
     if (!AllowDistCache)
     {
         HttpRuntime.Cache.Remove(CreateKey(key));
         return;
     }
     DistCached.GetInstance(PORT_CACHE).Remove(key);
 }
Пример #7
0
 public static bool Add_MemCache(string key, object value, int timeOutInMinutes)
 {
     if (!AllowDistCache)
     {
         HttpRuntime.Cache.Insert(CreateKey(key), value, null, DateTime.Now.AddDays(15), TimeSpan.Zero);
         return(true);
     }
     return(DistCached.GetInstance(PORT_CACHE).Add(key, value, (long)1000 * 60 * timeOutInMinutes));
 }
Пример #8
0
 public static bool IsCacheExists(int parentCatId, string key)
 {
     if (IsAllowDistributedCached)
     {
         return(DistCached.GetInstance(parentCatId).Get(key) != null);
     }
     else
     {
         return(false);
     }
 }
Пример #9
0
 public static object GetCache(int parentCatId, string key)
 {
     if (IsAllowDistributedCached)
     {
         //Lib.WriteLogToFile(DistCached.GetProvidersState());
         DateTime start = DateTime.Now;
         object   data  = DistCached.GetInstance(parentCatId).Get(key);
         DateTime end   = DateTime.Now;
         Lib.WriteLogToFile(key + "(" + (end.Ticks - start.Ticks).ToString() + "): " + end.ToString("HH:mm:ss.FFFFFFF") + "     " + start.ToString("HH:mm:ss.FFFFFFF"));
         return(data);
     }
     else
     {
         return(null);
     }
 }
Пример #10
0
 public static void Add(int parentCatId, string key, object value, long timeExpire)
 {
     if (IsAllowDistributedCached)
     {
         string lastUpdateKey = string.Format(Constants.CACHE_NAME_LAST_UPDATE, key);
         if (timeExpire > 0)
         {
             DistCached.GetInstance(parentCatId).Add(key, value, timeExpire * 1000);
             DistCached.GetInstance(parentCatId).Add(lastUpdateKey, DateTime.Now.ToString(), timeExpire * 1000);
         }
         else
         {
             DistCached.GetInstance(parentCatId).Add(key, value, _DefaultCacheExpire * 1000);
             DistCached.GetInstance(parentCatId).Add(lastUpdateKey, DateTime.Now.ToString(), _DefaultCacheExpire * 1000);
         }
     }
 }
Пример #11
0
        public static string Get_MemCache(string key)
        {
            return(null);

            try
            {
                if (!AllowDistCache)
                {
                    return(HttpRuntime.Cache.Get(CreateKey(key)).ToString());
                }
                return(DistCached.GetInstance(PORT_CACHE).Get(key).ToString());
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Пример #12
0
        public static T Get_MemCache <T>(string key)
        {
            return(default(T));

            try
            {
                if (!AllowDistCache)
                {
                    return((T)HttpRuntime.Cache.Get(CreateKey(key)));
                }
                return(DistCached.GetInstance(PORT_CACHE).Get <T>(key));
            }
            catch
            {
                return(default(T));
            }
        }
Пример #13
0
 public static T Get <T>(int parentCatId, string key)
 {
     if (IsAllowDistributedCached)
     {
         if (IsCacheExists(parentCatId, key))
         {
             DateTime start = DateTime.Now;
             T        data  = DistCached.GetInstance(parentCatId).Get <T>(key);
             DateTime end   = DateTime.Now;
             Lib.WriteLogToFile(key + "(" + (end.Ticks - start.Ticks).ToString() + "): " + end.ToString("HH:mm:ss.FFFFFFF") + "     " + start.ToString("HH:mm:ss.FFFFFFF"));
             return(data);
         }
         else
         {
             return(default(T));
         }
     }
     else
     {
         return(default(T));
     }
 }
Пример #14
0
        public static void Reset_MemCache()
        {
            if (!AllowDistCache)
            {
                var keys = new List <string>();
                // retrieve application Cache enumerator
                var cache      = HttpRuntime.Cache;
                var enumerator = cache.GetEnumerator();
                // copy all keys that currently exist in Cache
                while (enumerator.MoveNext())
                {
                    keys.Add(enumerator.Key.ToString());
                }
                // delete every key from cache
                foreach (var t in keys)
                {
                    cache.Remove(t);
                }
            }

            DistCached.GetInstance(PORT_CACHE).RemoveAll();
        }