示例#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
文件: CacheManager.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
文件: CacheManager.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
文件: CacheManager.cs 项目: JuRogn/OA
 public void Insert(object key, object value)
 {
     _itemsLock.EnterWriteLock();
     try
     {
         _items[key] = new WCFCacheItem(value);
     }
     finally
     {
         _itemsLock.ExitWriteLock();
     }
 }
示例#9
0
文件: CacheManager.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();
         }
     }
 }