Click or drag to resize

RecentDictionaryTKey, TValue Class

A collection of keys and values that tracks the order in which entries are accessed.
Inheritance Hierarchy
SystemObject
  Scaleout.CollectionsRecentDictionaryTKey, TValue

Namespace:  Scaleout.Collections
Assembly:  Scaleout.Collections (in Scaleout.Collections.dll) Version: 1.0.3.0 (1.0.3.0)
Syntax
C#
public sealed class RecentDictionary<TKey, TValue> : IDictionary<TKey, TValue>, 
	ICollection<KeyValuePair<TKey, TValue>>, IEnumerable<KeyValuePair<TKey, TValue>>, 
	IEnumerable

Type Parameters

TKey
The type of the keys in the dictionary.
TValue
The type of the values in the dictionary.

The RecentDictionaryTKey, TValue type exposes the following members.

Constructors
  NameDescription
Public methodRecentDictionaryTKey, TValue
Initializes a new instance of the dictionary that is empty, performs LRU eviction, has the default initial capacity, and uses the default equality comparer for the key type.
Public methodRecentDictionaryTKey, TValue(IEqualityComparerTKey)
Initializes a new instance of the dictionary that is empty, performs LRU eviction, has the default initial capacity, and uses the specified equality comparer for the key type.
Public methodRecentDictionaryTKey, TValue(Int32)
Initializes a new instance of the dictionary that is empty, performs LRU eviction, has the specified initial capacity, and uses the default equality comparer for the key type.
Public methodRecentDictionaryTKey, TValue(RecentDictionaryEvictionMode)
Initializes a new instance of the dictionary that is empty, uses the specified eviction mode, has the default initial capacity, and uses the default equality comparer for the key type.
Public methodRecentDictionaryTKey, TValue(Int32, IEqualityComparerTKey)
Initializes a new instance of the dictionary with the specified initial capacity, performs LRU eviction, and uses the provided equality comparer for the key type.
Public methodRecentDictionaryTKey, TValue(Int32, RecentDictionaryEvictionMode, IEqualityComparerTKey)
Initializes a new instance of the dictionary with the specified initial capacity, the specified eviction, and uses the provide equality comparer for the key type.
Top
Properties
  NameDescription
Public propertyCount
Gets the number of key/value pairs contained in the dictionary.
Public propertyItem
Gets or sets the value associated with the specified key, marking the entry as the most recently used.
Public propertyKeys
Gets a collection containing the keys in the dictionary.
Public propertyLeastRecent
Gets the least recently accessed item in the dictionary. The order of items in the dictionary is not modified.
Public propertyMostRecent
Gets the most recently accessed item in the dictionary. The order of items in the dictionary is not modified.
Public propertyValues
Gets a collection containing the values in the dictionary.
Top
Methods
  NameDescription
Public methodAdd
Adds the specified key and value to the dictionary.
Public methodClear
Removes all items from the dictionary without changing the dictionary's capacity.
Public methodContainsKey
Determines whether the dictionary contains the specified key. The order of items in the dictionary is not modified.
Public methodContainsValue
Determines whether the dictionary contains the specified value. The order of items in the dictionary is not modified.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodGetEnumerator
Returns an enumerator that iterates through the dictionary.
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodRemove
Removes the value with the specified key from the dictionary.
Public methodRemoveAndGetLeastRecent
Gets and removes the least recently accessed item from the dictionary.
Public methodRemoveAndGetMostRecent
Gets and removes the most recently accessed item from the dictionary.
Public methodRemoveLeastRecent
Removes the least recently accessed item from the dictionary.
Public methodRemoveMostRecent
Removes the most recently accessed item from the dictionary.
Public methodSetAndMaintainCount
Adds/updates the dictionary with a new value. If the operation performs an add, either the least-recently or most-recently accessed element will be removed to make room for the new one (depending on the RecentDictionaryEvictionMode passed into the constructor).
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Public methodTrim
Trims excess capacity from the dictionary.
Public methodTryGetValue
Gets the value associated with the specified key.
Top
Remarks

This dictionary is intended to be used as a building block for caches that perform LRU eviction. The SetAndMaintainCount(TKey, TValue) method is the primary method for this use case. It allows entries to be added/updated in the dictionary and removes either the least-recently-used or most-recently-used item if the operation results in an add to prevent unbounded growth.

Caution note Caution
Unlike a standard .NET dictionary, this collection does not tolerate multiple concurrent readers. Retrieving a value from this collection changes the entry's position in the internal LRU list and therefore modifies the dictionary's state. Be sure to use a lock in multithreaded scenarios.
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
See Also