Method InsertBulk
InsertBulk(IDictionary<String, CacheItem>, WriteThruOptions)
Inserts a dictionary of cache keys with Cache
Declaration
IDictionary<string, Exception> InsertBulk(IDictionary<string, CacheItem> items, WriteThruOptions writeThruOptions = null)
Parameters
Type | Name | Description |
---|---|---|
System. |
items | Dictionary of keys and Cache |
Write |
writeThruOptions | Write |
Returns
Type | Description |
---|---|
System. |
Dictionary of keys along with exception that were unable to store in cache. |
Remarks
If the key or multilple keys already exist, this overload overwrites the values of the existing ICache items. If the key does not exist, it adds the item to the cache.
Examples
The following example demonstrates how to insert items to the cache with an absolute expiration of 2 minutes from now, a priority of 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.InsertBulk(items, writeThruOptions);