Method AddExclusive
AddExclusive(TKey, TValue, CreatePolicy, IEnumerable<string>, CancellationToken)
Add an object in the cache and exclusively locks it, returning a CacheResponse<TKey, TValue> containing a lock token.
public CacheResponse<TKey, TValue> AddExclusive(TKey key, TValue value, CreatePolicy createPolicy = null, IEnumerable<string> tags = null, CancellationToken cancellationToken = default)
Parameters
key
TKeyIdentifier of the object in the cache.
value
TValueValue to be stored in the cache.
createPolicy
CreatePolicyThe policy to be associated with the new object. If
null
, the default policy for the cache will be used.tags
IEnumerable<string>Collection of tags to associate with the object. Pass null for no tags.
cancellationToken
CancellationTokenA token used to propagate notification that this operation should be canceled.
Returns
- CacheResponse<TKey, TValue>
A CacheResponse<TKey, TValue> containing the outcome of the operation and a lock token that can be used for subsequent locking operations against the newly added object.
Remarks
The Result property of the response will contain one of the following ServerResult outcomes:
ServerResult | Description |
---|---|
Added | A new object was successfully added in the ScaleOut service and was left in a locked state. |
AlreadyExistsError | The object could not be added because another object with the same key already exists in the ScaleOut service. |
Use the lock token on the response's LockToken property to perform subsequent operations under the lock.