/// <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); } }
/// <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); } }
/// <summary> /// Initializes a new instance of the <see cref="ExpirableItemDictionary<K, T>"/> 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); }
/// <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); } }
/// <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); } }
/// <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); }
/// <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); } }
/// <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); } }
/// <summary> /// Adds a new expirable item to the collection. /// </summary> protected void Add(TKey key, ExpirableItem <TValue> value) { innerDictionary.Add(key, value); }