![]() | RecentDictionaryTKey, TValue Class |
Namespace: Scaleout.Collections
public sealed class RecentDictionary<TKey, TValue> : IDictionary<TKey, TValue>, ICollection<KeyValuePair<TKey, TValue>>, IEnumerable<KeyValuePair<TKey, TValue>>, IEnumerable
The RecentDictionaryTKey, TValue type exposes the following members.
Name | Description | |
---|---|---|
![]() | RecentDictionaryTKey, 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.
|
![]() | RecentDictionaryTKey, 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.
|
![]() | RecentDictionaryTKey, 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.
|
![]() | RecentDictionaryTKey, 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.
|
![]() | RecentDictionaryTKey, 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.
|
![]() | RecentDictionaryTKey, 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.
|
Name | Description | |
---|---|---|
![]() | Count |
Gets the number of key/value pairs contained in the dictionary.
|
![]() | Item |
Gets or sets the value associated with the specified key, marking the entry
as the most recently used.
|
![]() | Keys |
Gets a collection containing the keys in the dictionary.
|
![]() | LeastRecent |
Gets the least recently accessed item in the dictionary. The order of
items in the dictionary is not modified.
|
![]() | MostRecent |
Gets the most recently accessed item in the dictionary. The order of
items in the dictionary is not modified.
|
![]() | Values |
Gets a collection containing the values in the dictionary.
|
Name | Description | |
---|---|---|
![]() | Add |
Adds the specified key and value to the dictionary.
|
![]() | Clear |
Removes all items from the dictionary without changing the dictionary's capacity.
|
![]() | ContainsKey |
Determines whether the dictionary contains the specified key. The order of
items in the dictionary is not modified.
|
![]() | ContainsValue |
Determines whether the dictionary contains the specified value. The order of
items in the dictionary is not modified.
|
![]() | Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) |
![]() | GetEnumerator |
Returns an enumerator that iterates through the dictionary.
|
![]() | GetHashCode | Serves as the default hash function. (Inherited from Object.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | Remove |
Removes the value with the specified key from the dictionary.
|
![]() | RemoveAndGetLeastRecent |
Gets and removes the least recently accessed item from the dictionary.
|
![]() | RemoveAndGetMostRecent |
Gets and removes the most recently accessed item from the dictionary.
|
![]() | RemoveLeastRecent |
Removes the least recently accessed item from the dictionary.
|
![]() | RemoveMostRecent |
Removes the most recently accessed item from the dictionary.
|
![]() | SetAndMaintainCount |
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).
|
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
![]() | Trim |
Trims excess capacity from the dictionary.
|
![]() | TryGetValue |
Gets the value associated with the specified key.
|
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.
![]() |
---|
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. |