Class RefCountedConcurrentDictionary<TKey, TValue>
Represents a thread-safe collection of reference-counted key/value pairs that can be accessed by multiple threads concurrently. Values that don't yet exist are automatically created using a caller supplied value factory method, and when their final refcount is released they are removed from the dictionary.
Inherited Members
Namespace: SixLabors.ImageSharp.Web.Synchronization
Assembly: SixLabors.ImageSharp.Web.dll
Syntax
public class RefCountedConcurrentDictionary<TKey, TValue> where TKey : notnull where TValue : class
Type Parameters
Name | Description |
---|---|
TKey | The type of the key. |
TValue | The value for the dictionary. |
Constructors
| Edit this page View SourceRefCountedConcurrentDictionary(IEqualityComparer<TKey>, Func<TKey, TValue>, Action<TValue>?)
Initializes a new instance of the RefCountedConcurrentDictionary<TKey, TValue> class that is empty, has the default concurrency level and capacity,, and uses the specified IEqualityComparer<T>.
Declaration
public RefCountedConcurrentDictionary(IEqualityComparer<TKey> comparer, Func<TKey, TValue> valueFactory, Action<TValue>? valueReleaser)
Parameters
Type | Name | Description |
---|---|---|
IEqualityComparer<TKey> | comparer | The IEqualityComparer<T> implementation to use when comparing keys. |
Func<TKey, TValue> | valueFactory | Factory method that generates a new |
Action<TValue> | valueReleaser | Optional callback that is used to cleanup |
RefCountedConcurrentDictionary(Func<TKey, TValue>, Action<TValue>?)
Initializes a new instance of the RefCountedConcurrentDictionary<TKey, TValue> class that is empty, has the default concurrency level, has the default initial capacity, and uses the default comparer for the key type.
Declaration
public RefCountedConcurrentDictionary(Func<TKey, TValue> valueFactory, Action<TValue>? valueReleaser = null)
Parameters
Type | Name | Description |
---|---|---|
Func<TKey, TValue> | valueFactory | Factory method that generates a new |
Action<TValue> | valueReleaser | Optional callback that is used to cleanup |
RefCountedConcurrentDictionary(int, int, IEqualityComparer<TKey>, Func<TKey, TValue>, Action<TValue>?)
Initializes a new instance of the RefCountedConcurrentDictionary<TKey, TValue> class that is empty, has the specified concurrency level, has the specified initial capacity, and uses the specified IEqualityComparer<T>.
Declaration
public RefCountedConcurrentDictionary(int concurrencyLevel, int capacity, IEqualityComparer<TKey> comparer, Func<TKey, TValue> valueFactory, Action<TValue>? valueReleaser)
Parameters
Type | Name | Description |
---|---|---|
int | concurrencyLevel | The estimated number of threads that will access the RefCountedConcurrentDictionary<TKey, TValue> concurrently |
int | capacity | The initial number of elements that the RefCountedConcurrentDictionary<TKey, TValue> can contain. |
IEqualityComparer<TKey> | comparer | The IEqualityComparer<T> implementation to use when comparing keys. |
Func<TKey, TValue> | valueFactory | Factory method that generates a new |
Action<TValue> | valueReleaser | Optional callback that is used to cleanup |
RefCountedConcurrentDictionary(int, int, Func<TKey, TValue>, Action<TValue>?)
Initializes a new instance of the RefCountedConcurrentDictionary<TKey, TValue> class that is empty, has the specified concurrency level and capacity, and uses the default comparer for the key type.
Declaration
public RefCountedConcurrentDictionary(int concurrencyLevel, int capacity, Func<TKey, TValue> valueFactory, Action<TValue>? valueReleaser = null)
Parameters
Type | Name | Description |
---|---|---|
int | concurrencyLevel | The estimated number of threads that will access the RefCountedConcurrentDictionary<TKey, TValue> concurrently |
int | capacity | The initial number of elements that the RefCountedConcurrentDictionary<TKey, TValue> can contain. |
Func<TKey, TValue> | valueFactory | Factory method that generates a new |
Action<TValue> | valueReleaser | Optional callback that is used to cleanup |
Methods
| Edit this page View SourceGet(TKey)
Obtains a reference to the value corresponding to the specified key. If no such value exists in the dictionary, then a new value is generated using the value factory method supplied in the constructor. To prevent leaks, this reference MUST be released via Release(TKey).
Declaration
public TValue Get(TKey key)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key of the element to add ref. |
Returns
Type | Description |
---|---|
TValue | The referenced object. |
Release(TKey)
Releases a reference to the value corresponding to the specified key. If this reference was the last remaining reference to the value, then the value is removed from the dictionary, and the optional value releaser callback is invoked.
Declaration
public void Release(TKey key)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | THe key of the element to release. |