Insert a CacheItem to the cache asynchoronously

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

Syntax

C#
public virtual void InsertAsync(
	string key,
	CacheItem item,
	DSWriteOption dsWriteOption,
	DataSourceItemsUpdatedCallback onDataSourceItemUpdatedCallback
)
Visual Basic
Public Overridable Sub InsertAsync ( 
	key As String,
	item As CacheItem,
	dsWriteOption As DSWriteOption,
	onDataSourceItemUpdatedCallback As DataSourceItemsUpdatedCallback
)
Visual C++
public:
virtual 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.
 Copy imageCopy
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
 Copy imageCopy
Cache cache = NCache.InitializeCache("myCache");
cache.InsertAsync("DSN", item, DSWriteOption.WriteThru, new DataSourceItemsUpdatedCallback(onDSItemsUpdated));

See Also