예제 #1
0
 public void Insert(object key, object value, DateTime expirationDate, TimeSpan slidingExpirationTime)
 {
     _itemsLock.EnterWriteLock();
     try
     {
         _items[key] = new WCFCacheItem(value, expirationDate, slidingExpirationTime);
     }
     finally
     {
         _itemsLock.ExitWriteLock();
     }
 }
예제 #2
0
 public void Insert(object key, object value)
 {
     _itemsLock.EnterWriteLock();
     try
     {
         _items[key] = new WCFCacheItem(value);
     }
     finally
     {
         _itemsLock.ExitWriteLock();
     }
 }
예제 #3
0
 public object this[object key]
 {
     get
     {
         if (key == null)
         {
             return(null);
         }
         _itemsLock.EnterUpgradeableReadLock();
         try
         {
             WCFCacheItem res = (WCFCacheItem)_items[key];
             if (res != null)
             {
                 if (res.SlidingExpirationTime.TotalMilliseconds > 0)
                 {
                     _itemsLock.EnterWriteLock();
                     try
                     {
                         res.LastAccessTime = DateTime.Now;
                     }
                     finally
                     {
                         _itemsLock.ExitWriteLock();
                     }
                 }
                 return(res.ItemValue);
             }
             else
             {
                 return(null);
             }
         }
         finally
         {
             _itemsLock.ExitUpgradeableReadLock();
         }
     }
     set
     {
         _itemsLock.EnterWriteLock();
         try
         {
             _items[key] = new WCFCacheItem(value);
         }
         finally
         {
             _itemsLock.ExitWriteLock();
         }
     }
 }
예제 #4
0
        private void CacherefreshTimerCallback(object state)
        {
            _itemsLock.EnterUpgradeableReadLock();
            try
            {
                Dictionary <object, WCFCacheItem> delItems = new Dictionary <object, WCFCacheItem>();
                DateTime dtNow = DateTime.Now;
                foreach (DictionaryEntry de in _items)
                {
                    WCFCacheItem ci = (WCFCacheItem)de.Value;
                    if (ci.ExpirationDate < dtNow)
                    {
                        delItems.Add(de.Key, ci);
                    }
                    else
                    {
                        if (ci.SlidingExpirationTime.TotalMilliseconds > 0)
                        {
                            if (dtNow.Subtract(ci.LastAccessTime).TotalMilliseconds > ci.SlidingExpirationTime.TotalMilliseconds)
                            {
                                delItems.Add(de.Key, ci);
                            }
                        }
                    }
                }

                if (delItems.Count > 0)
                {
                    _itemsLock.EnterWriteLock();
                    try
                    {
                        foreach (KeyValuePair <object, WCFCacheItem> kvp in delItems)
                        {
                            if (_items.ContainsKey(kvp.Key))
                            {
                                _items.Remove(kvp.Key);
                            }
                        }
                    }
                    finally
                    {
                        _itemsLock.ExitWriteLock();
                    }
                }
            }
            finally
            {
                _itemsLock.ExitUpgradeableReadLock();
            }
        }
예제 #5
0
        public void Insert(object key, object value, int Minutes)
        {
            DateTime expirationDate = DateTime.Now.AddMinutes(Minutes);

            _itemsLock.EnterWriteLock();
            try
            {
                _items[key] = new WCFCacheItem(value, expirationDate);
            }
            finally
            {
                _itemsLock.ExitWriteLock();
            }
        }
예제 #6
0
파일: CacheHelper.cs 프로젝트: JuRogn/OA
 public void Insert(object key, object value, DateTime expirationDate, TimeSpan slidingExpirationTime)
 {
     _itemsLock.EnterWriteLock();
     try
     {
         _items[key] = new WCFCacheItem(value, expirationDate, slidingExpirationTime);
     }
     finally
     {
         _itemsLock.ExitWriteLock();
     }
 }
예제 #7
0
파일: CacheHelper.cs 프로젝트: JuRogn/OA
 public void Insert(object key, object value, int Minutes)
 {
     DateTime expirationDate = DateTime.Now.AddMinutes(Minutes);
     _itemsLock.EnterWriteLock();
     try
     {
         _items[key] = new WCFCacheItem(value, expirationDate);
     }
     finally
     {
         _itemsLock.ExitWriteLock();
     }
 }
예제 #8
0
파일: CacheHelper.cs 프로젝트: JuRogn/OA
 public void Insert(object key, object value)
 {
     _itemsLock.EnterWriteLock();
     try
     {
         _items[key] = new WCFCacheItem(value);
     }
     finally
     {
         _itemsLock.ExitWriteLock();
     }
 }
예제 #9
0
파일: CacheHelper.cs 프로젝트: JuRogn/OA
 public object this[object key]
 {
   
     get
     {
         if (key == null)
             return null;
         _itemsLock.EnterUpgradeableReadLock();
         try
         {
             WCFCacheItem res = (WCFCacheItem)_items[key];
             if (res != null)
             {
                 if (res.SlidingExpirationTime.TotalMilliseconds > 0)
                 {
                     _itemsLock.EnterWriteLock();
                     try
                     {
                         res.LastAccessTime = DateTime.Now;
                     }
                     finally
                     {
                         _itemsLock.ExitWriteLock();
                     }
                 }
                 return res.ItemValue;
             }
             else
             {
                 return null;
             }
         }
         finally
         {
             _itemsLock.ExitUpgradeableReadLock();
         }
     }
     set
     {
         _itemsLock.EnterWriteLock();
         try
         {
             _items[key] = new WCFCacheItem(value);
         }
         finally
         {
             _itemsLock.ExitWriteLock();
         }
     }
 }