Method InsertBulk
InsertBulk(IDictionary<String, CacheItem>, WriteThruOptions)
Inserts 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> InsertBulk(IDictionary<string, CacheItem> items, WriteThruOptions writeThruOptions = null)
Parameters
Type | Name | Description |
---|---|---|
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 |
---|---|
IDictionary<System.String, Exception> | 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 2 minutes from now, a priority of high, and that notifies the application when the item is removed from the cache.
ICache cache = CacheManager.GetCache("myCache");
CacheItem[] cacheItems = new CacheItem[2];
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);