Windows Server AppFabric caching supports the notion of pessimistic concurrency implementation by placing locks on the cache items that are expected to be within the scope of subsequent updates by more than one possible caching client. This is in total contrast to optimistic concurrency, where there are no locks and each cache client is allowed to modify the cache item. Of course, this is only as long as there is no cache item version number mismatch.
The following are three key API calls available on DataCache
that support pessimistic concurrency (via locks):
GetAndLock
PutAndLock
UnLock
When the lock is acquired, it returns a (lock) handle to the cache client. For example, for GetAndLock
calls, once a particular cache client has a lock handle, no other cache client will be able to invoke a GetAndLock
call (for as long as the lock is valid and alive there is a timeout associated with each lock and we will discuss this later in the recipe).
It should be...