Method RemoveAsync
RemoveAsync<T>(String, WriteThruOptions)
Removes an item from the cache asynchronously with a cache key to reference its location and WriteThruOptions.
Declaration
Task<T> RemoveAsync<T>(string key, WriteThruOptions writeThruOptions = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | Unique key of the item to be removed. |
WriteThruOptions | writeThruOptions | WriteThruOptions regarding updating the data source. This can be either WriteThru, WriteBehind or None. |
Returns
Type | Description |
---|---|
Task<T> | Task that performs a remove operation in the background. Once completed returns the item that was removed from the cache. Task Status property can be used to determine status of the task that can be IsCanceled, IsCompleted, and IsFaulted. |
Type Parameters
Name | Description |
---|---|
T | Specifies the type of value obtained from the cache. |
Examples
The following example demonstrates how you can remove an item from your application's Alachisoft.NCache.Client.Cache object asynchronously.
ICache cache = CacheManager.GetCache("myCache");
string key = "Product0";
WriteThruOptions writeThruOptions = new WriteThruOptions(WriteMode.WriteThru, "ProdDataSource1");
cache.RemoveAsync<Product>(key, writeThruOptions).ContinueWith(task => OnItemRemoved(key, task));
private static void OnItemRemoved(string key, Task<Product> task)
{
if (task.Status == TaskStatus.RanToCompletion)
{
...
}
if (task.Status == TaskStatus.Faulted)
{
...
}
if (task.Exception != null)
{
...
}
}