Method Lock
Lock(String, TimeSpan, out LockHandle)
Acquires a lock on an item in the cache.
Declaration
bool Lock(string key, TimeSpan lockTimeout, out LockHandle lockHandle)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | Key of cached item to be locked. |
System.TimeSpan | lockTimeout | An instance of System.TimeSpan after which the lock is automatically released. |
LockHandle | lockHandle | An instance of LockHandle that will be filled in with the lock information, if lock is acquired successfully. |
Returns
Type | Description |
---|---|
System.Boolean | Whether or not lock was acquired successfully. |
Examples
The following example demonstrates how to lock a cached item.
ICache cache = CacheManager.GetCache("demoCache");
string key = "Product0";
LockHandle lockHandle = new LockHandle();
bool locked = cache.lock(key, new TimeSpan(0,0,10), out lockHandle);