Beispiel #1
0
 public static void SetDistributedCache(string cacheKey, object data, bool absoluteExpiration = true, int cacheExpirationMinutes = 30, string groupName = null)
 {
     if (absoluteExpiration)
     {
         MemcachedCacheHelper.Set(cacheKey, data, DateTime.Now.AddMinutes(cacheExpirationMinutes), groupName);
     }
     else
     {
         MemcachedCacheHelper.Set(cacheKey, data, TimeSpan.FromMinutes(cacheExpirationMinutes), groupName);
     }
 }
Beispiel #2
0
        public static T GetWithDistributedCache <T>(string cacheKey, Func <T> getter, bool absoluteExpiration = true, int cacheExpirationMinutes = 30, string groupName = null)
        {
            bool   found;
            object t = MemcachedCacheHelper.Get(cacheKey, out found);

            if (found)
            {
                return((T)t);
            }
            T data = getter();

            if (absoluteExpiration)
            {
                MemcachedCacheHelper.Set(cacheKey, data, DateTime.Now.AddMinutes(cacheExpirationMinutes), groupName);
            }
            else
            {
                MemcachedCacheHelper.Set(cacheKey, data, TimeSpan.FromMinutes(cacheExpirationMinutes), groupName);
            }
            return(data);
        }