Table of Contents

Class CachedSynchronizedDictionary<TKey, TValue>

Namespace
Ecng.Collections
Assembly
Ecng.Collections.dll

Represents a thread-safe dictionary with cached keys, values, and key-value pairs for improved performance.

public class CachedSynchronizedDictionary<TKey, TValue> : SynchronizedDictionary<TKey, TValue>, ISynchronizedCollection<KeyValuePair<TKey, TValue>>, ISynchronizedCollection, IDictionary<TKey, TValue>, ICollection<KeyValuePair<TKey, TValue>>, IEnumerable<KeyValuePair<TKey, TValue>>, IEnumerable

Type Parameters

TKey

The type of keys in the dictionary.

TValue

The type of values in the dictionary.

Inheritance
CachedSynchronizedDictionary<TKey, TValue>
Implements
IDictionary<TKey, TValue>
ICollection<KeyValuePair<TKey, TValue>>
IEnumerable<KeyValuePair<TKey, TValue>>
Derived
Inherited Members
Extension Methods

Constructors

CachedSynchronizedDictionary()

Initializes a new instance of the CachedSynchronizedDictionary<TKey, TValue> class.

public CachedSynchronizedDictionary()

CachedSynchronizedDictionary(IEqualityComparer<TKey>)

Initializes a new instance of the CachedSynchronizedDictionary<TKey, TValue> class with the specified equality comparer.

public CachedSynchronizedDictionary(IEqualityComparer<TKey> comparer)

Parameters

comparer IEqualityComparer<TKey>

The equality comparer to use when comparing keys.

CachedSynchronizedDictionary(int)

Initializes a new instance of the CachedSynchronizedDictionary<TKey, TValue> class with the specified initial capacity.

public CachedSynchronizedDictionary(int capacity)

Parameters

capacity int

The initial number of elements that the dictionary can contain.

CachedSynchronizedDictionary(int, IEqualityComparer<TKey>)

Initializes a new instance of the CachedSynchronizedDictionary<TKey, TValue> class with the specified initial capacity and equality comparer.

public CachedSynchronizedDictionary(int capacity, IEqualityComparer<TKey> comparer)

Parameters

capacity int

The initial number of elements that the dictionary can contain.

comparer IEqualityComparer<TKey>

The equality comparer to use when comparing keys.

Properties

CachedKeys

Gets an array of cached keys from the dictionary.

public TKey[] CachedKeys { get; }

Property Value

TKey[]

Remarks

The keys are cached for performance and are reset when the dictionary is modified.

CachedPairs

Gets an array of cached key-value pairs from the dictionary.

public KeyValuePair<TKey, TValue>[] CachedPairs { get; }

Property Value

KeyValuePair<TKey, TValue>[]

Remarks

The key-value pairs are cached for performance and are reset when the dictionary is modified.

CachedValues

Gets an array of cached values from the dictionary.

public TValue[] CachedValues { get; }

Property Value

TValue[]

Remarks

The values are cached for performance and are reset when the dictionary is modified.

this[TKey]

Gets or sets the value associated with the specified key.

public override TValue this[TKey key] { set; }

Parameters

key TKey

The key of the value to get or set.

Property Value

TValue

The value associated with the specified key.

Methods

Add(TKey, TValue)

Adds the specified key and value to the dictionary.

public override void Add(TKey key, TValue value)

Parameters

key TKey

The key of the element to add.

value TValue

The value of the element to add.

Clear()

Removes all keys and values from the dictionary.

public override void Clear()

OnResetCache(bool)

Resets the cached keys, values, and key-value pairs when the dictionary is modified.

protected virtual void OnResetCache(bool isKey)

Parameters

isKey bool

Indicates whether the cache reset is due to a key modification.

Remove(TKey)

Removes the value with the specified key from the dictionary.

public override bool Remove(TKey key)

Parameters

key TKey

The key of the element to remove.

Returns

bool

true if the element is successfully found and removed; otherwise, false.