Example #1
0
 public CacheItemHolder(
     T value,
     CacheSetting cacheItemInfo)
 {
     this.Value         = value;
     this.cacheItemInfo = cacheItemInfo;
 }
Example #2
0
        public void Set(string key, object value, CacheSetting itemInfo)
        {
            lock (thisLock)
            {
                DateTime expiredtime = DateTime.Now;

                switch (itemInfo.ExpirationMode)
                {
                case CacheExpirationMode.Absolute:
                    expiredtime = itemInfo.AbsoluteExpiration;
                    break;

                case CacheExpirationMode.Sliding:
                    expiredtime = expiredtime.Add(itemInfo.SlidingExpiration);
                    break;

                case CacheExpirationMode.Never:
                    client.Store(StoreMode.Set, key, value);
                    return;

                default:
                    break;
                }

                client.Store(StoreMode.Set, key, value, expiredtime);
            }
        }
Example #3
0
 public CacheItemHolder(
     CacheManager cache,
     CacheSetting cacheItemInfo)
 {
     this.cache         = cache;
     this.cacheItemInfo = cacheItemInfo;
 }
Example #4
0
        public void Set(
            string key,
            object value,
            CacheSetting itemInfo)
        {
            lock ( thisLock )
            {
                OnBeforeValueSet();

                inMemoryCache[key] =
                    new CacheItem(
                        key,
                        value,
                        itemInfo);

                LogCentral.Current.Debug(
                    string.Format(
                        @"[»º³å] ÔÚ'{0}' Ìí¼ÓÁËÒÔϵĻº³å×é: " +
                        @"¼ü(key) ='{1}', Öµ(value) '{2}'.",
                        DateTime.Now,
                        key,
                        inMemoryCache[key].Dump()));

                CheckCurrentSize();

                OnAfterValueSet();
            }
        }
Example #5
0
        public void Set(
            string key,
            object value,
            CacheSetting itemInfo)
        {
            lock (thisLock)
            {
                DateTime             expiredtime = DateTime.Now;
                ICacheItemExpiration expire      = null;
                switch (itemInfo.ExpirationMode)
                {
                case CacheExpirationMode.Absolute:
                    expiredtime = itemInfo.AbsoluteExpiration;
                    expire      = new CacheItemExpiration(expiredtime);
                    break;

                case CacheExpirationMode.Sliding:
                    expiredtime = expiredtime.Add(itemInfo.SlidingExpiration);
                    expire      = new SlidingCacheItemExpiration(itemInfo.SlidingExpiration);
                    break;

                case CacheExpirationMode.Never:
                    client.Add(key, value);
                    return;

                default:
                    break;
                }

                client.Add(key, value, CacheItemPriority.Normal, new NullCacheItemRefreshAction(), expire);
            }
        }
Example #6
0
 public CacheItem(
     string key,
     object value,
     CacheSetting cacheInfo)
 {
     this.key       = key;
     this.value     = value;
     this.cacheInfo = cacheInfo;
 }
Example #7
0
 public virtual void Set(
     string key,
     object value,
     TimeSpan ts)
 {
     lock (thisLock)
     {
         CacheSetting cs = new CacheSetting();
         cs.AbsoluteExpiration = DateTime.Now.Add(ts);
         Set(key, value, cs);
     }
 }
Example #8
0
 public virtual void Set(
     string key,
     object value,
     DateTime absoluteDateTime)
 {
     lock (thisLock)
     {
         CacheSetting cs = new CacheSetting();
         cs.AbsoluteExpiration = absoluteDateTime;
         Set(key, value, cs);
     }
 }
Example #9
0
 public virtual void Set(
     string key,
     object value,
     CacheSetting itemInfo)
 {
     lock ( thisLock )
     {
         if (backer != null)
         {
             backer.Set(key, value, itemInfo);
         }
     }
 }
Example #10
0
 public CacheItemHolder(
     CacheSetting cacheItemInfo)
 {
     this.cacheItemInfo = cacheItemInfo;
 }