Insert a CacheItem to the cache asynchoronously

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 void InsertAsync(
	string key,
	CacheItem item,
	DSWriteOption dsWriteOption,
	DataSourceItemsUpdatedCallback onDataSourceItemUpdatedCallback
)
Visual Basic
Public Sub InsertAsync ( _
	key As String, _
	item As CacheItem, _
	dsWriteOption As DSWriteOption, _
	onDataSourceItemUpdatedCallback As DataSourceItemsUpdatedCallback _
)
Visual C++
public:
void InsertAsync(
	String^ key, 
	CacheItem^ item, 
	DSWriteOption dsWriteOption, 
	DataSourceItemsUpdatedCallback^ onDataSourceItemUpdatedCallback
)

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
onDataSourceItemUpdatedCallback
Type: Alachisoft.NCache.Web.Caching..::..DataSourceItemsUpdatedCallback
A delegate that, if provided, is called when item is updated in 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 insert an item into the cache asynchronously. It also provides the option to udpate the data source and registers a delegate to get the result of the data source operation.
CopyC#
CacheItem item = new CacheItem(connectionString);
item.AbsoluteExpiration = DateTime.Now.AddMinutes(2);
item.SlidingExpiration = TimeSpan.Zero;
item.Priority = CacheItemPriority.High;
item.ItemRemoveCallback = onRemove;
item.AsyncItemUpdateCallback = OnAsyncItemUpdated;
Then insert CacheItem to the cache
CopyC#
Cache cache = NCache.InitializeCache("myCache");
cache.InsertAsync("DSN", item, DSWriteOption.WriteThru, new DataSourceItemsUpdatedCallback(onDSItemsUpdated));

See Also