Esempio n. 1
0
 private static void CacheExpireMoni()
 {
     try
     {
         var      v     = dicCache.Values.OrderBy((itm) => { return(itm.ExpireTime); }).Take(20);
         DateTime dtNow = DateTime.Now;
         foreach (var c in v)
         {
             if ((dtNow - c.CacheStartTime).TotalMinutes > c.ExpireTime)
             {
                 AppCache.Remove(c.Key);
             }
         }
     }
     catch { }
 }
Esempio n. 2
0
        public static T GetCache <T>(object key)
        {
            var nkey = key.Equals(Thread.CurrentThread.ManagedThreadId) ? key : $"{key}_{DAO.DBNo}";

            dicCache.TryGetValue(nkey, out CacheObject obj);
            if (obj == null)
            {
                return(default(T));
            }
            if ((DateTime.Now - obj.CacheStartTime).TotalMinutes > obj.ExpireTime)
            {
                AppCache.Remove(nkey);
                return(default(T));
            }
            return((T)obj.Value);
        }
Esempio n. 3
0
        public static bool ContainsKey(object key)
        {
            var nkey = key.Equals(Thread.CurrentThread.ManagedThreadId) ? key : $"{key}_{DAO.DBNo}";

            if (dicCache.ContainsKey(nkey))
            {
                CacheObject cobj;
                if (dicCache.TryGetValue(nkey, out cobj))
                {
                    if ((DateTime.Now - cobj.CacheStartTime).TotalMinutes > cobj.ExpireTime)
                    {
                        AppCache.Remove(nkey);
                        return(false);
                    }
                }
            }
            return(dicCache.ContainsKey(nkey));
        }