Retrieves the specified item from the Cache object if it is not already locked. Otherwise returns null (Nothing in Visual Basic). This is different from the normal Get operation where an item is returned ignoring the lock altogether.

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

Syntax

C#
public virtual Object Get(
	string key,
	TimeSpan lockTimeout,
	ref LockHandle lockHandle,
	bool acquireLock
)
Visual Basic
Public Overridable Function Get ( _
	key As String, _
	lockTimeout As TimeSpan, _
	ByRef lockHandle As LockHandle, _
	acquireLock As Boolean _
) As Object
Visual C++
public:
virtual Object^ Get(
	String^ key, 
	TimeSpan lockTimeout, 
	LockHandle^% lockHandle, 
	bool acquireLock
)

Parameters

key
Type: System..::..String
The identifier for the cache item to retrieve.
lockTimeout
Type: System..::..TimeSpan
The TimeSpan after which the lock is automatically released.
lockHandle
Type: Alachisoft.NCache.Web.Caching..::..LockHandle%
An instance of LockHandle to hold the lock information.
acquireLock
Type: System..::..Boolean
A flag to determine whether to acquire a lock or not.

Return Value

The retrieved cache item, or a null reference (Nothing in Visual Basic) if the key is not found.

Remarks

Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.

Examples

The following example demonstrates how to retrieve the cached value and acquire a lock at the same time.
CopyC#
Cache theCache = NCache.InitializeCache("myreplicatedcache");
theCache.Add("cachedItemKey", new CacheItem("cachedItemValue"));

LockHandle lockHandle = new LockHandle();

object cachedItem = theCache.Get("cachedItemKey", Cache.NoLockingExpiration, ref lockHandle, true);

Exceptions

ExceptionCondition
System..::..ArgumentNullExceptionkey contains a null reference (Nothing in Visual Basic).
System..::..ArgumentExceptionkey is is an empty string.

See Also