Cache.Insert Method (String, Object, CacheDependency, DateTime, TimeSpan, CacheItemUpdateCallback)
Inserts an object into the Cache object together with dependencies, expiration policies, and a delegate that you can use to notify the application before the item is removed from the cache.
Assembly: System.Web (in System.Web.dll)
public void Insert( string key, object value, CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemUpdateCallback onUpdateCallback )
The cache key that is used to reference the object.
The object to insert into the cache.
The file or cache key dependencies for the item. When any dependency changes, the object becomes invalid and is removed from the cache. If there are no dependencies, this parameter contains null.
The time at which the inserted object expires and is removed from the cache. To avoid possible issues with local time such as changes from standard time to daylight saving time, use UtcNow instead of Now for this parameter value. If you are using absolute expiration, the slidingExpiration parameter must be set to NoSlidingExpiration.
The interval between the time that the cached object was last accessed and the time at which that object expires. If this value is the equivalent of 20 minutes, the object will expire and be removed from the cache 20 minutes after it was last accessed. If you are using sliding expiration, the absoluteExpiration parameter must be set to NoAbsoluteExpiration.
A delegate that will be called before the object is removed from the cache. You can use this to update the cached item and ensure that it is not removed from the cache.
The key, value, or onUpdateCallback parameter is null.
You set the slidingExpiration parameter to less than TimeSpan.Zero or the equivalent of more than one year.
Themethod enables you to insert a new item in the cache and provide a delegate that is called before the item is removed from the cache. In the delegate, you can update the cached item and thereby prevent it from being removed from the cache.
This method will overwrite an existing Cache item with the same key parameter.
You cannot set both the absoluteExpiration and slidingExpiration parameters. If you intend the cache item to expire at a specific time, you set the absoluteExpiration parameter to the specific time, and the slidingExpiration parameter to NoSlidingExpiration.
If you intend the cache item to expire after a set period of time since the item was last accessed, you set the slidingExpiration parameter to the expiration interval, and you set the absoluteExpiration parameter to NoAbsoluteExpiration.
Available since 2.0