NCache 4.6 - Online Documentation

Updating Data with Registered Callback Method

 
In order to get a notification upon execution of an update operation, AsyncItemUpdatedCallback needs to be registered with InsertAsync operation in NCache. It is demonstrated in the example below.
 
      To utilize the API, include the following namespace in your application: Alachisoft.NCache.Web.Caching.
 
        Product product = new Product();
        product.ProductID = 1001;
        product.ProductName = "Chai";
        product.Category = 5; // updated category
 
        CacheItem cacheItem = new CacheItem(product);
        cacheItem.AsyncItemUpdateCallback += new AsyncItemUpdatedCallback(OnItemUpdated);
 
        string key = "Product:" +product.ProductID;
 
        try
        {
            cache.InsertAsync(key, cacheItem, DSWriteOption.None, null);
        }
        catch (Exception ex)
        {
            // handle exception
        }
 
        //Create a callback
        public static void OnItemUpdate(string key, object status)
        {
          if (status.ToString().Equals("Success"))
          {   
//do something
          }
          if (status.ToString().Equals("Failure"))
          {   
//do something
          }
          if (status is Exception)
          {   
//do something
          }
        }
 
 
 
See Also