Gets or sets the cache item at the specified key.

Namespace: Alachisoft.NCache.Web.Caching
Assembly: Alachisoft.NCache.Web (in Alachisoft.NCache.Web.dll) Version: 4.1.0.0 (4.1.0.0)

Syntax

C#
public override Object this[
	string key
] { get; set; }
Visual Basic
Public Overrides Default Property Item ( _
	key As String _
) As Object
	Get
	Set
Visual C++
public:
virtual property Object^ default[String^ key] {
	Object^ get (String^ key) override;
	void set (String^ key, Object^ value) override;
}

Parameters

key
Type: System..::..String
A string object that represents the key for the cache item.

Field Value

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 incase of failure.

Examples

The following examples demonstrates using this property to retrieve and insert the values of cached item.
CopyC#
void cmdReset_Click(object objSender, EventArgs objArgs)
{
    txtValue.Text = NCache.Cache[txtName.Text].ToString();
}

void cmdAdd_Click(object objSender, EventArgs objArgs)
{
    if (txtName.Text != "")
    {
        // Add this item to the cache.
        NCache.Cache[txtName.Text] = txtValue.Text;
    }
}
Or simply in a class deriving from [!:Alachisoft.NCache.Web.UI.NPage] or [!:Alachisoft.NCache.Web.UI.NUserControl].
CopyC#
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

ExceptionCondition
System..::..ArgumentNullExceptionkey or value contains a null reference (Nothing in Visual Basic).
System..::..ArgumentExceptionkey or value is not serializable.

See Also