Using Write-Behind with Basic Operations
Adding with Write-Behind
Member | Description |
---|---|
CacheItemVersion Add(string key, CacheItem item, DSWriteOption dsWriteOption, string providerName, DataSourceItemsAddedCallback onDataSourceItemAdded) |
Adds item in cache using the specified provider and Write-Behind option |
- Add without Callback Method
string key = "Customer:David:1001";
CacheItem cacheItem = new CacheItem(new Product());
try{
cache.Add(key, cacheItem, DSWriteOption.WriteBehind, null);
}
catch (Exception exp){
//Operation fails if the item already exists
// Request is not sent to the backing source in
}
- Add with Callback Method
protected void OnDataSourceItemsAdded(IDictionary iDict)
{
//Perform appropriate actions upon response
}
private void AddTest()
{
string key = "Customer:David:1001";
CacheItem cacheItem = new CacheItem(new Product());
try{
cache.Add(key, cacheItem, DSWriteOption.WriteBehind, OnDataSourceItemsAdded);
//Verify item added in cache and in main source
}
catch (Exception exp){
//Operation fails if the item already exists
}
}
Updating Existing Data with Write-Behind
Member | Description |
---|---|
CacheItemVersion Insert(string key, CacheItem item, DSWriteOption dsWriteOption, string providerName, DataSourceItemsUpdatedCallback onDataSourceItemUpdatedCallback); |
Adds item in cache using the default provider and Write-Behind option |
CacheItemVersion Insert(string key, CacheItem item, DSWriteOption dsWriteOption, string providerName, DataSourceItemsUpdatedCallback onDataSourceItemUpdatedCallback); |
Adds item in cache using the specified provider and Write-Behind option |
protected void OnDataSourceItemsUpdated(IDictionary iDict)
{
//Perform appropriate actions upon response
}
private void UpdateTest()
{
string key = "Customer:David:1001";
cacheItem.SubGroup = "WriteThru-Test";
try{
cache.Insert(key, cacheItem, DSWriteOption.WriteBehind, OnDataSourceItemsUpdated);
}
catch (Exception exp){
//handle exception
}
}
Deleting Existing Data with Write-Behind
Member | Description |
---|---|
Delete(string key, DSWriteOption dsWriteOption, DataSourceItemsRemovedCallback onDataSourceItemRemovedCallback); |
Deletes item in cache using the default provider and Write-Behind option |
Delete(string key, DSWriteOption dsWriteOption, string providerName,DataSourceItemsRemovedCallback onDataSourceItemRemovedCallback); |
Deletes item in cache using the specified provider and Write-Behind option |
protected void OnDataSourceItemsRemoved(IDictionary iDict)
{
//Perform appropriate actions upon response
}
private void DeleteTest()
{
string key = "Customer:David:1001";
try{
cache.Delete(key, DSWriteOption.WriteBehind, OnDataSourceItemsRemoved);
//Verify the removed item from both cache and data source
}
catch (OperationFailedException exp){
//Operation fails if key does not exist in the cache
}
}
See Also
Configuring WriteThru Provider
Using Write-Behind with Bulk Operations
Using Write-Behind with Asynchronous Operations