Using Write-Behind with Asynchronous Operations
Add New Item Asynchronously
Member | Description |
---|---|
AddAsync(string key, CacheItem item, DSWriteOption dsWriteOption, DataSourceItemsAddedCallback onDataSourceItemAdded); |
Adds item asynchronously in cache using the default provider and Write-Behind option |
void AddAsync(string key, CacheItem item, DSWriteOption dsWriteOption, string providerName, DataSourceItemsAddedCallback onDataSourceItemAdded) |
Adds item asynchronously in cache using Custom Provider and Write-Behind option |
protected void OnDataSourceItemsAdded(IDictionary iDict)
{
//Perform appropriate actions upon response
}
private void AsyncAddTest()
{
try
{
string key = "Customer:David:1001";
CacheItem cacheItem = new CacheItem(new Product());
cache.AddAsync(key, cacheItem, DSWriteOption.WriteBehind, OnDataSourceItemsAdded);
//verify that the key is added in Cache and master source
}
catch (Exception exp)
{
//handle exception
}
}
Update Existing Item Asynchronously
Member | Description |
---|---|
void InsertAsync(string key, CacheItem item, DSWriteOption dsWriteOption, DataSourceItemsUpdatedCallback onDataSourceItemUpdatedCallback) |
Updates existing item asynchronously in cache using the default provider |
void InsertAsync(string key, CacheItem item, string providerName, DSWriteOption dsWriteOption, DataSourceItemsUpdatedCallback onDataSourceItemUpdatedCallback) |
Updates existing item asynchronously in cache using the specified provider |
protected void OnDataSourceItemsUpdated(IDictionary iDict)
{
//Perform appropriate actions upon response
}
private void AsyncUpdateTest()
{
Cache mycache = NCache.InitializeCache("myreplicatedcache");
try
{
string key = "Customer:David:1001";
CacheItem cacheItem = new CacheItem(new Product());
cacheItem.SubGroup = "Async-WriteThru-Test";
cache.InsertAsync(key, cacheItem, DSWriteOption.WriteBehind, OnDataSourceItemsUpdated);
//verify that the key is updated in Cache and master source
}
catch (Exception exp)
{
//handle exception
}
}
See Also
Configuring WriteThru Provider
Using Write-Behind with Basic Operations
Using Write-Behind with Bulk Operations