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: 4.1.0.0 (4.1.0.0)

Syntax

C#
public virtual void Delete(
	string key,
	LockHandle lockHandle
)
Visual Basic
Public Overridable Sub Delete ( _
	key As String, _
	lockHandle As LockHandle _
)
Visual C++
public:
virtual void Delete(
	String^ key, 
	LockHandle^ lockHandle
)

Parameters

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

Examples

The following example demonstrates how to remove a locked item from the cache. First create a CacheItem.
CopyC#
Cache theCache = NCache.InitializeCache("myreplicatedcache");
Add an item int the cache.
CopyC#
theCache.Add("cachedItemKey", "cachedItemValue");
Create the lock-handle.
CopyC#
LockHandle lockHandle = new LockHandle();
Get the added item from cache and acquire a lock.
CopyC#
object cachedItem = theCache.Get("cachedItemKey", ref lockHandle, true);
if (cachedItem != null)
{
    try
    {
        //Now remove the cached item using lockHandle acquired earlier.
        object removedItem = theCache.Remove("cachedItemKey", lockHandle);
    }
    catch (OperationFailedException ex)
    {
        //Do something
    }
}

See Also