Skip to content

TryLock

Tries to acquire lock for a shared key.

1
$Cache.TryLock(key: string):string

Parameters

string key
    Shared lock key.

Returns

Token value in string if lock has acquired, otherwise null.

Remarks

This method immediately checks to shared key is locked and generates token if shared key is not locked. Does not perform any wait operation for availability, if you want to wait for short period, please use the Lock method instead.

Example

1
2
3
4
5
6
7
var tokenValue = $Cache.TryLock('mylock');
if (tokenValue != null) {
  // Locked code block 
  $Cache.ReleaseLock('mylock',tokenValue1);
} else {
  // Already locked  
}

See Also