NCache 4.6 - Online Documentation

Adding Data with Registered Callback Method

 
The AsyncItemAddedCallback function is used to register an asynchronous addition callback allowing the user to perform appropriate functions upon completion of the Add operation  in NCache.
 
In this example, an ItemAddedCallback provided by NCache needs to be registered with an AddAsync call.
 
      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";
 
        CacheItem cacheItem = new CacheItem(product);
        cacheItem.AsyncItemAddCallback += new AsyncItemAddedCallback(OnItemAdded);
 
        string key = "Product:" +product.ProductID ;
 
        try
        {
          cache.AddAsync(key, cacheItem, DSWriteOption.None, null);
        }
        catch (Exception ex)
        {
            // handle exception
        }
 
        //Create a callback
        public static void OnItemAdded(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