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.3.0.0 (4.3.0.0)

Syntax

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

Parameters

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

Property Value

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

Examples

The following examples demonstrates using this property to retrieve and insert the values of cached item.
 Copy imageCopy
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

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

See Also