Cache.Item Property (String)

 

Gets or sets the cache item at the specified key.

Namespace:   System.Web.Caching
Assembly:  System.Web (in System.Web.dll)

Public Property Item (
	key As String
) As Object

Parameters

key
Type: System.String

A String object that represents the key for the cache item.

Property Value

Type: System.Object

The specified cache item.

You can use this property to retrieve the value of a specified cache item, or to add an item and a key for it to the cache. Adding a cache item using the Item property is equivalent to calling the Cache.Insert method.

The following example uses the Item property to retrieve the value of a cached object associated with the Key1 key. It then uses the HttpResponse.Write method to write the value and introductory text and the B HTML element to a Web Forms page.

Response.Write("Value of cache key: <B>" + Server.HtmlEncode(CType(Cache("Key1"),String)) + "</B>")

The following example demonstrates using this property to insert the value of a text box into the cache.

Private Sub cmdAdd_Click(objSender As Object, objArgs As EventArgs)
  If txtName.Text <> "" Then
    ' Add this item to the cache.
  Cache(txtName.Text) = txtValue.Text
  End If
End Sub

.NET Framework
Available since 1.1
Return to top
Show: