NCache 4.6 - Online Documentation

Updating Item with Specific Version

In environments where multiple applications work on a single cache, item version can be used to ensure that the data which is updated is the same  as in cache and is not updated previously by any other cache client.
In this example, a previously cached item is updated by specifying item version. If the specified version is equal to the one in the cache, then it will be updated else OperationFailedException will be thrown by NCache.
      To utilize the API, include the following namespace in your application: Alachisoft.NCache.Web.Caching.
            //precondition:┬áitemVersion is saved when item was added in cache
            Product product = new Product();
            product.ProductID = 1001;
            product.ProductName = "Chai";
            product.Category = 5; // updated category
            CacheItem cacheItem = new CacheItem(product);
            string key = "Product:" + product.ProductID;
            //saved itemVersion from add item call
            cacheItem.Version = itemVersion;
                CacheItemVersion newVersion = cache.Insert(key, cacheItem);
                //save new version for future usage
                //verify the updated version and value in cache
            catch (OperationFailedException ex)
                // handle exception
See Also