Method TryAddAsync
TryAddAsync(string, string, TimeSpan, CancellationToken)
Adds a value under a key unless the key already has a value.
Declaration
public ValueTask<bool> TryAddAsync(string key, string value, TimeSpan lifetime, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | The key. |
| string | value | The value. |
| TimeSpan | lifetime | How long the value is kept. Must be positive. |
| CancellationToken | cancellationToken | A token to cancel the operation. |
Returns
| Type | Description |
|---|---|
| ValueTask<bool> | true if the value was added, or false if the key already has a value (or a counter). |