方法 RemoveAsync
移除异步(字符串,WriteThruOptions)
从缓存中异步删除项目,并使用缓存键来引用其位置和 WriteThruOptions。
声明
Task<T> RemoveAsync<T>(string key, WriteThruOptions writeThruOptions = null)
参数
| 类型 | 姓名 | 描述 |
|---|---|---|
| 系统字符串 | 键 | 要删除的项目的唯一键。 |
| 直写选项 | 写直通选项 | 直写选项 关于更新数据源。 这可以是 WriteThru、WriteBehind 或无。 |
Returns & Exchanges
| 类型 | 描述 |
|---|---|
| 系统.线程.任务.任务 | 在后台执行删除操作的任务。 完成后返回从缓存中删除的项目。 任务状态属性可用于确定任务的状态,可以是 IsCanceled、IsCompleted 和 IsFaulted。 |
类型参数
| 姓名 | 描述 |
|---|---|
| T | 指定从缓存中获取的值的类型。 |
例子
以下示例演示了如何从应用程序的 Alachisoft.NCache.Client.Cache 对象异步。
ICache cache = CacheManager.GetCache("demoClusteredCache");
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)
{
...
}
}