Appearance
GetOrAdd Method
Definition
- Namespace:
JASE.Caching - Assembly:
JASE.Caching.dll
TValue GetOrAdd(TKey key, Func<TKey, TValue> factory)
csharp
TValue GetOrAdd(TKey key, Func<TKey, TValue> factory)Gets the value for the specified key, or adds a new value created by factory if absent.
Parameters
| Name | Description |
|---|---|
factory | Factory used to create a value when the key is missing. |
key | The cache key. |
Returns
The existing or newly created value.
Remarks
If multiple threads race to add the same key, only one created value is stored. If TValue implements IDisposable, losing values are disposed immediately.