DataCache.GetAndLock Method (String, TimeSpan, DataCacheLockHandle, String)

 

Locks the key if the key is present and is not locked and returns the object corresponding to the key. For objects stored in regions. This overload is not supported in Windows Azure Shared Caching.

Namespace:   Microsoft.ApplicationServer.Caching
Assembly:  Microsoft.ApplicationServer.Caching.Client (in Microsoft.ApplicationServer.Caching.Client.dll)

Public Function GetAndLock (
	key As String,
	timeout As TimeSpan,
	<OutAttribute> ByRef lockHandle As DataCacheLockHandle,
	region As String
) As Object

Parameters

key
Type: System.String

The unique value that is used to identify the object in the region.

timeout
Type: System.TimeSpan

The amount of time that the object remains locked.

lockHandle
Type: Microsoft.ApplicationServer.Caching.DataCacheLockHandle

The DataCacheLockHandle object required to unlock the object. The lockHandle output parameter is passed by reference.

region
Type: System.String

The name of the region where the object resides.

Return Value

Type: System.Object

Returns Object matching the specified key parameter if the Object is present and is not locked.

  • If the key does not exist, a DataCacheException object is thrown with the ErrorCode set to KeyDoesNotExist. Create objects based on the referenced key to resolve this error.

  • If the object is already locked by another cache client, a DataCacheException object is thrown with the ErrorCode set to ObjectLocked. The object will be inaccessible until it is unlocked by the locking client.

Other GetAndLock method calls on the same object fail as long as the lock is valid. Regular Get method calls are not blocked and always access the latest version of the cached object.

Return to top
Show: