NCache 4.6 - Online Documentation

Locking Item while Performing Fetch Operation

 
An item while being retrieved  will be inaccessible for others unless it is released. In case of a mismatch of key, null is returned.
 
In this example, a key and a lockHandle for the key should be provided to fetch the cached object and lock it. “True” should be given if the user wants to acquire lock.
 
      To utilize the API, include the following namespace in your application: Alachisoft.NCache.Web.Caching.
 
            LockHandle lockHandle = new LockHandle();
 
            //Specify time span of 10 sec for which the item remains locked
            TimeSpan lockSpan = new TimeSpan(0, 0, 10);
 
            string key = "Product:1001";
 
            try
            {
                object result = cache.Get(key, lockSpan, ref lockHandle, true);
 
                if (result != null)
                {
                    if (result is Product)
                    {
                        Product product = (Product)result;
                    }
                }
            }
            catch (OperationFailedException ex)
            {
                // handle exception
            }
 
 
See Also