NCache 4.6 - Online Documentation

Releasing Lock with Update Operation

While updating an item in NCache, the lock can be released allowing other cache clients to use the cached data. In order to successfully release the locked item, the lockHandle initially used to lock the item must be specified. In case of an invalid or different handle, NCache would throw an OperationFailedException.
       To utilize the API, include the following namespace in your application: Alachisoft.NCache.Web.Caching.
            Product updatedProduct = new Product();
            updatedProduct.ProductID = 1001;
            updatedProduct.ProductName = "Chai";
            updatedProduct.Category = 4;
            string key = "Product" + updatedProduct.ProductID;
            LockHandle lockHandle = new LockHandle();
                //lock existing item for the time span of 30 seconds
                bool locked = cache.Lock(key, TimeSpan.FromSeconds(30), out lockHandle);
                if (locked)
                    cache.Insert(key, new CacheItem(updatedProduct), lockHandle, true);
            catch (OperationFailedException ex)
                // handle exception
See Also