Exemplo n.º 1
0
 /// <summary>
 /// 获取实例 (单例模式)
 /// </summary>
 /// <returns></returns>
 public static HttpRuntimeCacheHelper <V> GetInstance()
 {
     if (_instance == null)
     {
         lock (_instanceLock)
             if (_instance == null)
             {
                 _instance = new HttpRuntimeCacheHelper <V>();
             }
     }
     return(_instance);
 }
Exemplo n.º 2
0
        public V GetOrCreate <V>(string cacheKey, Func <V> create, int cacheDurationInSeconds = int.MaxValue)
        {
            var cacheManager = HttpRuntimeCacheHelper <V> .GetInstance();

            if (cacheManager.ContainsKey(cacheKey))
            {
                return(cacheManager[cacheKey]);
            }
            else
            {
                var result = create();
                cacheManager.Add(cacheKey, result, cacheDurationInSeconds);
                return(result);
            }
        }
Exemplo n.º 3
0
 public void Remove <V>(string key)
 {
     HttpRuntimeCacheHelper <V> .GetInstance().Remove(key);
 }
Exemplo n.º 4
0
 public IEnumerable <string> GetAllKey <V>()
 {
     return(HttpRuntimeCacheHelper <V> .GetInstance().GetAllKey());
 }
Exemplo n.º 5
0
 public V Get <V>(string key)
 {
     return(HttpRuntimeCacheHelper <V> .GetInstance().Get(key));
 }
Exemplo n.º 6
0
 public bool ContainsKey <V>(string key)
 {
     return(HttpRuntimeCacheHelper <V> .GetInstance().ContainsKey(key));
 }
Exemplo n.º 7
0
 public void Add <V>(string key, V value, int cacheDurationInSeconds)
 {
     HttpRuntimeCacheHelper <V> .GetInstance().Add(key, value, cacheDurationInSeconds);
 }
Exemplo n.º 8
0
 public void Add <V>(string key, V value)
 {
     HttpRuntimeCacheHelper <V> .GetInstance().Add(key, value);
 }