/// <summary>
/// Inserts an item into the <see cref="Cache"/> object with a specified lifetime using a cache key to reference its location.
/// </summary>
/// <param name="key">The cache key used to reference the item.</param>
/// <param name="value">The object to be inserted into the cache.</param>
/// <param name="lifetime">The lifetime of the inserted item (i.e. is it expendable or not).</param>
public void Insert(object key, object value, CacheItemLifetime lifetime)
{
if (key != null)
{
_rwl.AcquireWriterLock(LOCK_TIMEOUT_MSECS);
try
{
// remove any existing item for this key
CacheCollectionElement element = _data[key] as CacheCollectionElement;
if (element != null)
{
element.IsCollectable = true;
_data.Remove(key);
}
// add new item
element = new CacheCollectionElement(value, lifetime);
_data[key] = element;
}
finally
{
_rwl.ReleaseWriterLock();
}
}
else
{
throw new ArgumentNullException("key");
}
}