Inserts an object into the Cache with dependencies, expiration and priority policies.

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


public CacheItemVersion Insert(
	string key,
	Object value,
	CacheDependency dependency,
	DateTime absoluteExpiration,
	TimeSpan slidingExpiration,
	CacheItemPriority priority
Visual Basic
Public Function Insert ( _
	key As String, _
	value As Object, _
	dependency As CacheDependency, _
	absoluteExpiration As DateTime, _
	slidingExpiration As TimeSpan, _
	priority As CacheItemPriority _
) As CacheItemVersion
Visual C++
CacheItemVersion^ Insert(
	String^ key, 
	Object^ value, 
	CacheDependency^ dependency, 
	DateTime absoluteExpiration, 
	TimeSpan slidingExpiration, 
	CacheItemPriority priority


Type: System..::..String
The cache key used to reference the item.
Type: System..::..Object
The item to be added to the cache.
Type: Alachisoft.NCache.Runtime.Dependencies..::..CacheDependency
The file dependencies for the inserted object. When any dependency changes, the object becomes invalid and is removed from the cache. If there are no dependencies, this parameter contains a null reference (Nothing in Visual Basic).
Type: System..::..DateTime
The time at which the added object expires and is removed from the cache.
Type: System..::..TimeSpan
The interval between the time the added object was last accessed and when that object expires. If this value is the equivalent of 20 minutes, the object expires and is removed from the cache 20 minutes after it is last accessed.
Type: Alachisoft.NCache.Runtime..::..CacheItemPriority
The relative cost of the object, as expressed by the CacheItemPriority enumeration. The cache uses this value when it evicts objects; objects with a lower cost are removed from the cache before objects with a higher cost.


Note: If the key or value parameter is null, an ArgumentNullException is thrown. If you set the slidingExpiration parameter to less than Zero, or the equivalent of more than one year, an ArgumentOutOfRangeException is thrown. You cannot set both sliding and absolute expirations on the same cached item. If you do so, an ArgumentException is thrown.

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


The following example demonstrates how to assign an item high priority when you insert it into your application's Cache object.
Cache cache = NCache.InitializeCache("myCache");
cache.Insert("DSN", connectionString, null, DateTime.Now.AddMinutes(2), TimeSpan.Zero, CacheItemPriority.High);


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

See Also