Add a CacheItem to the cache asynchronously

Namespace: Alachisoft.NCache.Web.Caching
Assembly: Alachisoft.NCache.Web (in Alachisoft.NCache.Web.dll) Version: 4.1.0.0 (4.1.0.0)

Syntax

C#
public Object AddAsync(
	string key,
	CacheItem item,
	DSWriteOption dsWriteOption,
	DataSourceItemsAddedCallback onDataSourceItemAdded
)
Visual Basic
Public Function AddAsync ( _
	key As String, _
	item As CacheItem, _
	dsWriteOption As DSWriteOption, _
	onDataSourceItemAdded As DataSourceItemsAddedCallback _
) As Object
Visual C++
public:
Object^ AddAsync(
	String^ key, 
	CacheItem^ item, 
	DSWriteOption dsWriteOption, 
	DataSourceItemsAddedCallback^ onDataSourceItemAdded
)

Parameters

key
Type: System..::..String
The cache key used to reference the item.
item
Type: Alachisoft.NCache.Web.Caching..::..CacheItem
The item that is to be stored
dsWriteOption
Type: Alachisoft.NCache.Web.Caching..::..DSWriteOption
Options regarding updating data source
onDataSourceItemAdded
Type: Alachisoft.NCache.Web.Caching..::..DataSourceItemsAddedCallback
A delegate that, if provided, is called when item is added to data source.

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 an item to the cache with a sliding expiration of 5 minutes, a priority of high, and that notifies the application when the item is removed from the cache. First create a CacheItem.
CopyC#
CacheItem item = new CacheItem(timeStamp);
item.SlidingExpiration = new TimeSpan(0,5,0);
item.Priority = CacheItemPriority.High;
item.ItemRemoveCallback = onRemove;
Then add CacheItem to the cache
CopyC#
OnDataSourceItemAdded(IDictionary result)
{
...
}
Cache cache = NCache.InitializeCache("myCache");
   cache.AddAsync("timestamp", item, DSWriteOption.WriteBehind, new DataSourceItemsAddedCallback(OnDataSourceItemAdded));

See Also