NCache 4.6 - Online Documentation

Locking an Item Explicitly

Lock on an item can be acquired explicitly in NCache before performing any operation. Lock() method requires a TimeSpan to lock an item for a specified time. However, if you do not want the acquired lock to expire, simply specify a new TimeSpan(). The Lock() method used in this example associates a lockHandle. Kindly ensure that the single LockHandle is associated with a single key. Release the lock before re-using the handle; otherwise it might lead to inconsistency of behavior.
       To utilize the API, include the following namespace in your application: Alachisoft.NCache.Web.Caching.
            //create a new lock Handle
            LockHandle lockHandle = new LockHandle();
            string key = "Product:1001";
                // Specifying the time span of 10 sec for which the item remains locked
                bool locked = cache.Lock(key, new TimeSpan(0, 0, 10), out lockHandle);
            catch (OperationFailedException ex)
                // handle exception
See Also