Cache.Remove(String) 方法

定义

从应用程序的 Cache 对象移除指定项。Removes the specified item from the application's Cache object.

public:
 System::Object ^ Remove(System::String ^ key);
public object Remove (string key);
member this.Remove : string -> obj
Public Function Remove (key As String) As Object

参数

key
String

要移除的缓存项的 String 标识符。A String identifier for the cache item to remove.

返回

Cache 移除的项。The item removed from the Cache. 如果未找到键参数中的值,则返回 nullIf the value in the key parameter is not found, returns null.

示例

下面的示例创建一个RemoveItemFromCache方法。The following example creates a RemoveItemFromCache method. 调用此方法时, 它会使用Item[String]属性来检查缓存是否包含Key1与键值关联的对象。When this method is called, it uses the Item[String] property to check whether the cache contains an object that is associated with a Key1 key value. 如果是这样, Remove则调用方法以删除对象。If it does, the Remove method is called to remove the object.

public void RemoveItemFromCache(Object sender, EventArgs e) {
    if(Cache["Key1"] != null)
      Cache.Remove("Key1");
}
Public Sub RemoveItemFromCache(sender As Object, e As EventArgs)
    If (Not IsNothing(Cache("Key1"))) Then
      Cache.Remove("Key1")
    End If
End Sub

适用于

另请参阅