Method AddBulk
AddBulk(IDictionary<String, CacheItem>, WriteThruOptions)
Adds a dictionary of cache keys with CacheItem to the cache with the WriteThruOptions. The CacheItem contains properties to associate with the item, like expiration, dependencies and eviction information.
Declaration
IDictionary<string, Exception> AddBulk(IDictionary<string, CacheItem> items, WriteThruOptions writeThruOptions = null)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IDictionary<System.String, CacheItem> | items | Dictionary of keys and CacheItem. Keys must be unique. |
WriteThruOptions | writeThruOptions | WriteThruOptions regarding updating data source. This can be WriteThru, WriteBehind or None. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IDictionary<System.String, System.Exception> | Dictionary of Keys along with Exception that were unable to store in cache. |
Examples
The following example demonstrates how to add items in bulk to the cache. These items have absolute expiration of 2 minutes from now and have a priority of level high.
ICache cache = CacheManager.GetCache("demoClusteredCache");
CacheItem[] cacheItems = new CacheItem[3];
Product product_1 = new Product();
product_1.Id = 1;
product_1.Name = "Chai";
Product product_2 = new Product();
product_2.Id = 2;
product_2.Name = "Chang";
Product product_3 = new Product();
product_3.Id = 2;
product_3.Name = "Aniseed Syrup";
cacheItems[0] = new CacheItem(product_1);
cacheItems[0].Expiration = new Expiration(ExpirationType.Absolute, new TimeSpan(0, 2, 0));
cacheItems[0].Priority = CacheItemPriority.High;
cacheItems[1] = new CacheItem(product_2);
cacheItems[1].Expiration = new Expiration(ExpirationType.Absolute, new TimeSpan(0, 2, 0));
cacheItems[1].Priority = CacheItemPriority.Normal;
cacheItems[2] = new CacheItem(product_3);
cacheItems[2].Expiration = new Expiration(ExpirationType.Absolute, new TimeSpan(0, 2, 0));
cacheItems[2].Priority = CacheItemPriority.Low;
IDictionary<string, CacheItem> items = new Dictionary<string, CacheItem>()
{
{ "Product0",cacheItems[0]},
{ "Product1",cacheItems[1]},
{ "Product2",cacheItems[2]}
}
WriteThruOptions writeThruOptions = new WriteThruOptions(WriteMode.WriteThru, "ProdDataSource1");
cache.AddBulk(items, writeThruOptions);