Removes an item from cache if it is not already locked or if the correct lock-id is specified.

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


public virtual Object Remove(
	string key,
	LockHandle lockHandle
Visual Basic
Public Overridable Function Remove ( 
	key As String,
	lockHandle As LockHandle
) As Object
Visual C++
virtual Object^ Remove(
	String^ key, 
	LockHandle^ lockHandle


Type: System..::..String
key of item to be removed
Type: Alachisoft.NCache.Web.Caching..::..LockHandle
If the item is locked then, it can be removed only if the correct lockHandle is specified.

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).


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 int the cache.
 Copy imageCopy
theCache.Add("cachedItemKey", "cachedItemValue");
Create the lock-handle.
 Copy imageCopy
LockHandle lockHandle = new LockHandle();
Get the added item from cache and acquire a lock.
 Copy imageCopy
object cachedItem = theCache.Get("cachedItemKey", ref lockHandle, true);
if (cachedItem != null)
        //Now remove the cached item using lockHandle acquired earlier.
        object removedItem = theCache.Remove("cachedItemKey", lockHandle);
    catch (OperationFailedException ex)
        //Do something

See Also