Esempio n. 1
0
 /// <summary>
 /// Fast expiration. Since the ExpiringObject is ordered, the for-loop can break
 /// eaely if an object is not expired.
 /// </summary>
 /// <param name="segment">The segment.</param>
 private void ExpireSegment(CacheMap <TKey, ExpiringObject> segment)
 {
     //.NET-specific: iterate over KeyValuePairs
     foreach (var kvp in segment.ToList()) // iterate over copy
     {
         var expObj = kvp.Value;
         if (expObj.IsExpired)
         {
             segment.Remove(kvp.Key); // remove from original
             Logger.Debug("Removed in expire segment: {0}.", expObj.Value);
             _removedCounter.IncrementAndGet();
         }
         else
         {
             break;
         }
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Expires a key in a segment. If a key value pair is expired, it will get removed.
 /// </summary>
 /// <param name="segment">The segment.</param>
 /// <param name="key">The key.</param>
 /// <param name="value">The value.</param>
 /// <returns>True, if expired. False, otherwise.</returns>
 private bool Expire(CacheMap <TKey, ExpiringObject> segment, TKey key, ExpiringObject value)
 {
     if (value.IsExpired)
     {
         lock (segment)
         {
             var tmp = segment.Get(key);
             if (tmp != null && tmp.Equals(value))
             {
                 segment.Remove(key);
                 Logger.Debug("Removed in expire: {0}.", value.Value);
                 _removedCounter.IncrementAndGet();
             }
         }
         return(true);
     }
     return(false);
 }