Exemplo n.º 1
0
 /// <summary>
 /// 添加缓存(键不存在则添加,存在则替换)
 /// </summary>
 /// <param name="key">键</param>
 /// <param name="value">值</param>
 /// <param name="minutes">缓存时间(分钟)</param>
 /// <returns></returns>
 public static bool AddCache(CachedKey key, object value, int minutes = 10)
 {
     if (!IsUsedCache)
         return false;
     if (minutes <= 0)
         return Mc.Store(StoreMode.Set, key.ToString(), value);
     return Mc.Store(StoreMode.Set, key.ToString(), value, DateTime.Now.AddMinutes(minutes));
 }
Exemplo n.º 2
0
        /// <summary>
        /// 获取缓存
        /// </summary>
        /// <param name="key">键</param>
        /// <returns>返回缓存,没有找到则返回null</returns>
        public static object GetCache(CachedKey key)
        {
            if (!IsUsedCache)
                return null;

            try
            {
                return Mc.Get(key.ToString());
            }
            catch (Exception)
            {
                return null;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 是否存在该缓存
        /// </summary>
        /// <param name="key">键</param>
        /// <returns></returns>
        public static bool IsExists(CachedKey key)
        {
            if (!IsUsedCache)
                return false;

            return Mc.Get(key.ToString()) != null;
        }
Exemplo n.º 4
0
        /// <summary>
        /// 删除缓存(如果键不存在,则返回false)
        /// </summary>
        /// <param name="key">键</param>
        /// <returns>成功:true失败:false</returns>
        public static bool DelCache(CachedKey key)
        {
            if (!IsUsedCache)
                return false;

            return Mc.Remove(key.ToString());
        }