Jaa


DataCache.GetAndLock Method (String, TimeSpan, out 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.

Namespace: Microsoft.ApplicationServer.Caching
Assembly: Microsoft.ApplicationServer.Caching.Client (in microsoft.applicationserver.caching.client.dll)

Usage

'Usage
Dim instance As DataCache
Dim key As String
Dim timeout As TimeSpan
Dim lockHandle As DataCacheLockHandle
Dim region As String
Dim returnValue As Object

returnValue = instance.GetAndLock(key, timeout, lockHandle, region)

Syntax

'Declaration
Public Function GetAndLock ( _
    key As String, _
    timeout As TimeSpan, _
    <OutAttribute> ByRef lockHandle As DataCacheLockHandle, _
    region As String _
) As Object
public Object GetAndLock (
    string key,
    TimeSpan timeout,
    out DataCacheLockHandle lockHandle,
    string region
)
public:
Object^ GetAndLock (
    String^ key, 
    TimeSpan timeout, 
    [OutAttribute] DataCacheLockHandle^% lockHandle, 
    String^ region
)
public Object GetAndLock (
    String key, 
    TimeSpan timeout, 
    /** @attribute OutAttribute() */ /** @ref */ DataCacheLockHandle lockHandle, 
    String region
)

Parameters

  • key
    The unique value that is used to identify the object in the region.
  • timeout
    The amount of time that the object remains locked.
  • lockHandle
    The DataCacheLockHandle object required to unlock the object. The lockHandle output parameter is passed by reference.
  • region
    The name of the region where the object resides.

Return Value

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.

Remarks

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. For more information about concurrency, see Concurrency Models and Concurrency Methods.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Platforms

Development Platforms

Visual Studio 2010 and later, .NET Framework 4

Target Platforms

Windows 7; Windows Server 2008 R2; Windows Server 2008 Service Pack 2; Windows Vista Service Pack 2

See Also

Reference

DataCache Class
DataCache Members
Microsoft.ApplicationServer.Caching Namespace

  ff425062(v=azure.10).md 2011-08-26