Inserts an item into the Cache object with a cache key to reference its location and using default values provided by the CacheItemPriority enumeration.

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 CacheItemVersion Insert(
	string key,
	Object value
)
Visual Basic
Public Function Insert ( _
	key As String, _
	value As Object _
) As CacheItemVersion
Visual C++
public:
CacheItemVersion^ Insert(
	String^ key, 
	Object^ value
)

Parameters

key
Type: System..::..String
The cache key used to reference the item.
value
Type: System..::..Object
The item to be added to the cache.

Remarks

This method will overwrite an existing Cache item with the same key parameter.

Note: If the key or value parameter is null, an ArgumentNullException is thrown.

Note: If exceptions are enabled through the ExceptionsEnabled setting, this property throws exception incase of failure.

Examples

The following example demonstrates how to insert an item into an application's cache.
CopyC#
Cache cache = NCache.InitializeCache("myCache");
cache.Insert("DSN", connectionString);

Exceptions

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

See Also