Beispiel #1
0
        /// <summary>
        /// 读与写CACHE
        /// </summary>
        /// <example>
        /// <code>
        /// var list = Cache2.Get&lt;IList&lt;CachedItem>>(key, 1440, () => {
        ///     return Cache2.GetList();
        /// })
        /// </code>
        /// </example>
        /// <typeparam name="T">数据类型</typeparam>
        /// <param name="key">键</param>
        /// <param name="cacheTime">时间</param>
        /// <param name="acquire">动作</param>
        /// <returns></returns>
        public static T Get <T>(string key, int cacheTime, Func <T> acquire)
        {
            if (Cache2.ContainsKey(key))
            {
                return(Cache2.Get <T>(key));
            }

            T result = acquire();

            _cache.Insert(key, result, cacheTime);
            return(result);
        }
Beispiel #2
0
 /// <summary>
 /// 删除CACHE
 /// </summary>
 /// <param name="prefix"></param>
 /// <param name="delCache"></param>
 public static void Remove(string prefix, string[] delCache)
 {
     if (delCache.IsNull())
     {
         return;
     }
     foreach (string s in delCache)
     {
         if (s.IndexOf("(") == -1 || s.IndexOf("[") == -1)
         {
             Cache2.Remove(s.IndexOf("Cache_") == -1 ? prefix + s : s);
         }
         else
         {
             Cache2.RemoveByPattern(s.IndexOf("Cache_") == -1 ? "(" + prefix + s + ")" : s);
         }
     }
 }
 /// <summary>
 /// 取CACHE数据
 /// </summary>
 /// <typeparam name="T">源类型</typeparam>
 /// <param name="key">object扩展</param>
 /// <returns>取CACHE数据</returns>
 public static T FromCache <T>(this string key)
 {
     return((T)Cache2.Get(key));
 }
 /// <summary>
 /// 保存CACHE
 /// </summary>
 /// <param name="value">object扩展</param>
 /// <param name="key">保存CACHE</param>
 public static void ToCache(this object value, string key)
 {
     Cache2.Insert(key, value);
 }