Gets or sets the cache item at the specified key.
Namespace: Alachisoft.NCache.Web.CachingAssembly: Alachisoft.NCache.Web (in Alachisoft.NCache.Web.dll) Version: 4.1.0.0 (4.1.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.
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#
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
Exception | Condition |
---|---|
System..::..ArgumentNullException | key or value contains a null reference (Nothing in Visual Basic). |
System..::..ArgumentException | key or value is not serializable. |