Updating a Collection to Cache
An existing collection of items can be updated with the help of InsertBulk method.
Product product1 = new Product();
product1.ProductID = 1001;
product1.ProductName = "Chai";
product1.UnitsInStock = 5; //updated units
string key1 = "Product:" + product1.ProductID;
Product product2 = new Product();
product2.ProductID = 1002;
product2.ProductName = "Chang";
product2.UnitsInStock = 6; //updated units
string key2 = "Product:" + product2.ProductID;
string[] keys = { key1, key2 };
CacheItem[] items = new CacheItem[2];
items[0] = new CacheItem(product1);
items[1] = new CacheItem(product2);
try{
IDictionary result = cache.InsertBulk(keys, items, DSWriteOption.None, null);
}
catch (Exception ex){
// handle exception
}