Add a CacheItem to the cache

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,
	CacheItem item,
	DSWriteOption dsWriteOption,
	DataSourceItemsUpdatedCallback onDataSourceItemUpdatedCallback
)
Visual Basic
Public Overridable Function Insert ( 
	key As String,
	item As CacheItem,
	dsWriteOption As DSWriteOption,
	onDataSourceItemUpdatedCallback As DataSourceItemsUpdatedCallback
) As CacheItemVersion
Visual C++
public:
virtual CacheItemVersion^ Insert(
	String^ key, 
	CacheItem^ item, 
	DSWriteOption dsWriteOption, 
	DataSourceItemsUpdatedCallback^ onDataSourceItemUpdatedCallback
)

Parameters

key
Type: System..::..String
The cache key used to reference the item.
item
Type: Alachisoft.NCache.Web.Caching..::..CacheItem
The item that is to be stored
dsWriteOption
Type: Alachisoft.NCache.Web.Caching..::..DSWriteOption
Options regarding updating data source
onDataSourceItemUpdatedCallback
Type: Alachisoft.NCache.Web.Caching..::..DataSourceItemsUpdatedCallback
A delegate that, if provided, is called when item is updated in data source.

Return Value

Type: CacheItemVersion
An instance of CacheItemVersion

Remarks

If CacheItem contains invalid values the related exception is thrown. See CacheItem for invalid property values and related exceptions

Examples

The following example demonstrates how to add an item to the cache with a sliding expiration of 5 minutes, a priority of high, and that notifies the application when the item is removed from the cache. First create a CacheItem.
 Copy imageCopy
CacheItem item = new CacheItem(timeStamp);
item.SlidingExpiration = new TimeSpan(0,5,0);
item.Priority = CacheItemPriority.High;
item.ItemRemoveCallback = onRemove;
Then add CacheItem to the cache
 Copy imageCopy
Cache cache = NCache.InitializeCache("myCache");
   cache.Insert("timestamp", item, DSWriteOption.WriteThru, new DataSourceItemsUpdatedCallback(OnDSItemsUpdated));

See Also