Removes an item from cache if the specified version is still the most recent version in 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 Object Remove(
	string key,
	CacheItemVersion version
)
Visual Basic
Public Overridable Function Remove ( 
	key As String,
	version As CacheItemVersion
) As Object
Visual C++
public:
virtual Object^ Remove(
	String^ key, 
	CacheItemVersion^ version
)

Parameters

key
Type: System..::..String
key of item to be removed
version
Type: Alachisoft.NCache.Web.Caching..::..CacheItemVersion
The version of the item to be removed. The item is removed from the cache only if this is still the most recent version in the cache.

Return Value

Type: Object
The item removed from the Cache. If the value in the key parameter is not found, returns a null reference (Nothing in Visual Basic).

Examples

The following example demonstrates how to remove a locked item from the cache. First create a CacheItem.
 Copy imageCopy
Cache theCache = NCache.InitializeCache("myreplicatedcache");
Add an item in the cache.
 Copy imageCopy
theCache.Add("cachedItemKey", new "cachedItemValue");
Create the CacheItemVersion.
 Copy imageCopy
CacheItemVersion version = new CacheItemVersion();
Get the added item from cache and get the item version.
 Copy imageCopy
object cachedItem = theCache.Get("cachedItemKey", DSReadOption.None, ref version);
if (cachedItem != null)
{
    try
    {
        //Now remove the cached item using version acquired earlier.
        object removedItem = theCache.Remove("cachedItemKey", version);
    }
    catch (OperationFailedException ex)
    {
        //Do something
    }
}

See Also