Property Item
Item[String]
Gets or sets the cache item at the specified key.
Declaration
public virtual object this[string key] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
System.String | key | A |
Property Value
Type | Description |
---|---|
System.Object | The specified cache item. |
Remarks
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.
Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception in case of failure.
Examples
The following examples demonstrates using this property to retrieve and insert the values of cached item.
Cache cache = NCache.InitializeCache("myCache");
void cmdReset_Click(object objSender, EventArgs objArgs)
{
txtValue.Text = cache[txtName.Text].ToString();
}
void cmdAdd_Click(object objSender, EventArgs objArgs)
{
if (txtName.Text != "")
{
// Add this item to the cache.
cache[txtName.Text] = txtValue.Text;
}
}
void cmdReset_Click(object objSender, EventArgs objArgs)
{
txtValue.Text = cache[txtName.Text].ToString();
}
void cmdAdd_Click(object objSender, EventArgs objArgs)
{
if (txtName.Text != "")
{
// Add this item to the cache.
cache[txtName.Text] = txtValue.Text;
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentException |
|