Example #1
0
 /// <summary>
 /// Sets the <typeparamref name="T"/> value with the specified key and time-to-live.
 /// </summary>
 /// <value></value>
 public T this[K key, TimeSpan timeToLive]
 {
     set
     {
         _innerDictionary[key] = new ExpirableItem <T>(value, timeToLive);
     }
 }
Example #2
0
 /// <summary>
 /// Sets the <typeparamref name="T"/> value with the specified key an explicit expiration date/time.
 /// </summary>
 /// <value></value>
 public T this[K key, DateTime expires]
 {
     set
     {
         _innerDictionary[key] = new ExpirableItem <T>(value, expires);
     }
 }
Example #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ExpirableItemDictionary&lt;K, T&gt;"/> class.
        /// </summary>
        public ExpirableItemDictionary()
        {
            DefaultTimeToLive = new ExpirableItem <T>().TimeToLive;
            _innerDictionary  = new Dictionary <K, ExpirableItem <T> >();
            var ts = AutoClearExpiredItemsFrequency;

            this.Timer = new Timer(e => this.ClearExpiredItems(), null, ts, ts);
        }
Example #4
0
 /// <summary>
 ///     Gets or sets the <typeparamref name="TValue" /> value with the specified key.
 /// </summary>
 public TValue this[TKey key]
 {
     get
     {
         TValue value;
         if (!TryGetValue(key, out value))
         {
             throw new KeyNotFoundException();
         }
         return(value);
     }
     set { innerDictionary[key] = new ExpirableItem <TValue>(value, DefaultTimeToLive); }
 }
Example #5
0
 /// <summary>
 /// Gets or sets the <typeparamref name="T"/> value with the specified key.
 /// </summary>
 /// <value></value>
 public T this[K key]
 {
     get
     {
         lock (lockObject)
         {
             if (ContainsKey(key))
             {
                 return(_innerDictionary[key].Value);
             }
             return(default(T));
         }
     }
     set
     {
         _innerDictionary[key] = new ExpirableItem <T>(value, DefaultTimeToLive);
     }
 }
Example #6
0
 /// <summary>
 /// Adds a new expirable item to the collection.
 /// </summary>
 /// <param name="key">The key.</param>
 /// <param name="value">The value.</param>
 public void Add(K key, ExpirableItem <T> value)
 {
     _innerDictionary.Add(key, value);
 }
Example #7
0
 /// <summary>
 ///     Sets the <typeparamref name="TValue" /> value with the specified key an explicit expiration date/time.
 /// </summary>
 /// <value></value>
 public TValue this[TKey key, DateTime expires]
 {
     set { innerDictionary[key] = new ExpirableItem <TValue>(value, expires); }
 }
Example #8
0
 /// <summary>
 ///     Sets the <typeparamref name="TValue" /> value with the specified key and time-to-live.
 /// </summary>
 /// <value></value>
 public TValue this[TKey key, TimeSpan timeToLive]
 {
     set { innerDictionary[key] = new ExpirableItem <TValue>(value, timeToLive); }
 }
Example #9
0
 /// <summary>
 ///     Adds a new expirable item to the collection.
 /// </summary>
 protected void Add(TKey key, ExpirableItem <TValue> value)
 {
     innerDictionary.Add(key, value);
 }