Acquire a lock on an item in cache.

Namespace: Alachisoft.NCache.Web.Caching
Assembly: Alachisoft.NCache.Web (in Alachisoft.NCache.Web.dll) Version: 4.3.0.0 (4.3.0.0)

Syntax

C#
public virtual bool Lock(
	string key,
	TimeSpan lockTimeout,
	out LockHandle lockHandle
)
Visual Basic
Public Overridable Function Lock ( 
	key As String,
	lockTimeout As TimeSpan,
	<OutAttribute> ByRef lockHandle As LockHandle
) As Boolean
Visual C++
public:
virtual bool Lock(
	String^ key, 
	TimeSpan lockTimeout, 
	[OutAttribute] LockHandle^% lockHandle
)

Parameters

key
Type: System..::..String
key of cached item to be locked.
lockTimeout
Type: System..::..TimeSpan
TimeSpan after which the lock is automatically released.
lockHandle
Type: Alachisoft.NCache.Web.Caching..::..LockHandle%
An instance of [!:Lockhandle] that will be filled in with the lock information if lock is acquired successfully.

Return Value

Type: Boolean
Whether or not lock was acquired successfully.

Examples

Following example demonstrates how to lock a cached item.
 Copy imageCopy
...
LockHandle lockHandle = new LockHandle();
bool locked = theCache.lock("cachedItemKey", new TimeSpan(0,0,10), out lockHandle);
...

See Also