Removes an item from cache if it is not already locked or if the correct lock-id is specified.
Namespace: Alachisoft.NCache.Web.CachingAssembly: Alachisoft.NCache.Web (in Alachisoft.NCache.Web.dll) Version: 4.1.0.0 (4.1.0.0)
Syntax
C# |
---|
public virtual Object Remove( string key, LockHandle lockHandle ) |
Visual Basic |
---|
Public Overridable Function Remove ( _ key As String, _ lockHandle As LockHandle _ ) As Object |
Visual C++ |
---|
public: virtual Object^ Remove( 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.
Return Value
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.
Add an item int the cache.
Create the lock-handle.
Get the added item from cache and acquire a lock.
CopyC#
Cache theCache = NCache.InitializeCache("myreplicatedcache");
CopyC#
theCache.Add("cachedItemKey", "cachedItemValue");
CopyC#
LockHandle lockHandle = new LockHandle();
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 } }