Exemple #1
0
 public void Insert(TKey key, TValue value)
 {
     if ((key != null) && (value != null))
     {
         Remove(key);
         lock (this.locker)
         {
             CacheExpire <TValue> data = new CacheExpire <TValue>(value, DateTime.Now);
             this.cacheDatas[key] = data;
         }
     }
 }
Exemple #2
0
 protected void TimerCall(object obj)
 {
     TKey[] keys = cacheDatas.Keys.ToArray();
     foreach (TKey key in keys)
     {
         CacheExpire <TValue> data = cacheDatas[key];
         if (data != null)
         {
             TimeSpan expire = DateTime.Now - data.VisitTime;
             if (expire.TotalMilliseconds > ExpireTime)
             {
                 lock (locker)
                 {
                     if (cacheDatas.ContainsKey(key))
                     {
                         this.cacheDatas.Remove(key);
                     }
                 }
             }
         }
     }
 }