Method AddBulk
AddBulk(String[], CacheItem[], DSWriteOption, DataSourceItemsAddedCallback)
Add array of CacheItem to the cache.Also lets you specify DSWriteOption. It enables you to register a callback for notification when an item is added in data source.
Declaration
public virtual IDictionary AddBulk(string[] keys, CacheItem[] items, DSWriteOption dsWriteOption, DataSourceItemsAddedCallback onDataSourceItemsAdded)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | keys | The cache keys used to reference the items. |
CacheItem[] | items | The items that are to be stored |
DSWriteOption | dsWriteOption | Options regarding updating data source |
DataSourceItemsAddedCallback | onDataSourceItemsAdded | A delegate that, if provided, is called when item is added to data source. |
Returns
Type | Description |
---|---|
System.Collections.IDictionary | keys that are added or that already exists in the cache and their status. |
Remarks
If CacheItem contains invalid values the related exception is thrown. See CacheItem for invalid property values and related exceptions
Examples
The following example demonstrates how to add 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.
First create a CacheItems.
string keys = {"First", "Second"};
CacheItem items = new CacheItem[2]
items[0] = new CacheItem(firstTimeStamp);
items[0].AbsoluteExpiration = DateTime.Now.AddMinutes(2);
items[0].Priority = CacheItemPriority.High;
items[0].ItemRemoveCallback = onRemove;
items[1] = new CacheItem(secondTimeStamp);
items[1].AbsoluteExpiration = DateTime.Now.AddMinutes(2);
items[1].Priority = CacheItemPriority.Low;
items[1].ItemRemoveCallback = onRemove;
Then add CacheItem to the cache
OnDataSourceItemAdded(IDictionary result)
{
...
}
Cache cache = NCache.InitializeCache("myCache");
cache.Add(keys, items, DSWriteOption.WriteBehind, new DataSourceItemsAddedCallback(OnDataSourceItemAdded));
AddBulk(String[], CacheItem[])
Add array of CacheItem to the cache.
Declaration
public virtual IDictionary AddBulk(string[] keys, CacheItem[] items)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | keys | The cache keys used to reference the items. |
CacheItem[] | items | The items that are to be stored |
Returns
Type | Description |
---|---|
System.Collections.IDictionary | keys that are added or that already exists in the cache and their status. |
Remarks
If CacheItem contains invalid values the related exception is thrown. See CacheItem for invalid property values and related exceptions
Examples
The following example demonstrates how to add 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.
First create a CacheItems.
string keys = {"First", "Second"};
CacheItem items = new CacheItem[2]
items[0] = new CacheItem(firstTimeStamp);
items[0].AbsoluteExpiration = DateTime.Now.AddMinutes(2);
items[0].Priority = CacheItemPriority.High;
items[0].ItemRemoveCallback = onRemove;
items[1] = new CacheItem(secondTimeStamp);
items[1].AbsoluteExpiration = DateTime.Now.AddMinutes(2);
items[1].Priority = CacheItemPriority.Low;
items[1].ItemRemoveCallback = onRemove;
Then add CacheItem to the cache
OnDataSourceItemAdded(IDictionary result)
{
...
}
Cache cache = NCache.InitializeCache("myCache");
cache.Add(keys, items);
AddBulk(String[], CacheItem[], DSWriteOption, String, DataSourceItemsAddedCallback)
Add array of CacheItem to the cache. The data source provider name can be specified along with the option regarding data updating. A delegate that, if provided, is called when item is added to data source
Declaration
public virtual IDictionary AddBulk(string[] keys, CacheItem[] items, DSWriteOption dsWriteOption, string providerName, DataSourceItemsAddedCallback onDataSourceItemsAdded)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | keys | The cache keys used to reference the items. |
CacheItem[] | items | The items that are to be stored |
DSWriteOption | dsWriteOption | Options regarding updating data source |
System.String | providerName | A unique identifier for the data source |
DataSourceItemsAddedCallback | onDataSourceItemsAdded | A delegate that, if provided, is called when item is added to data source |
Returns
Type | Description |
---|---|
System.Collections.IDictionary | keys that are added or that already exists in the cache and their status. |