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

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

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.
namedTags
Type: Alachisoft.NCache.Runtime.Caching..::..NamedTagsDictionary
A NamedTagsDictionary to associate with the object.

Return Value

Type: CacheItemVersion
An instance of CacheItemVersion

Remarks

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 add an item into an application's cache.
 Copy imageCopy
Cache cache = NCache.InitializeCache("myCache");
NamedTagsDictionary namedTags = new NamedTagsDictionary();
namedTags.Add("Attribute", "value");
cache.Insert("DSN", connectionString, namedTags);

Exceptions

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

See Also