NCache 4.6 - Online Documentation

Remove Data from Cache

 
NCache provides two methods (remove, delete) to delete an item from cache.
 
      To utilize the APIs, include the following namespace in your application: Alachisoft.NCache.Web.Caching.
 
Difference between the Delete and Remove methods
 
Delete Method    
Remove Method
Returns void after deletion.
Deletes data from the cache and returns deleted data to the application.
 
For Delete/Remove API calls, if a backing source is configured and Write-Through is enabled, all the keys passed onto the Cache via the API will first be looked into and deleted from the Cache and irrespective of the key mapping, the call will be forwarded to the backing source.
 
If the desired mode is set to Write-Behind, and call backs are configured, you will receive them for the successful execution of the provider upon all the given keys.
 
Using Remove Method
 
A Remove method is a basic method which removes the key from the cache and returns the removed object to the cache.
 
        string key = "Product:1001";
        Product product = null;
 
        try
        {
            // null is returned if key does not exist in cache
            object result = cache.Remove(key);
 
            if (result != null)
            {
                if (result is Product)
                {
                    product = (Product)result;
                }
            }
        }
        catch (OperationFailedException ex)
        {
            // handle exception
        }
 
 
Using Delete Method
 
A delete method is a basic method which deletes the key from the cache.
 
        string key = "Product:1001";
 
        try
        {
            cache.Delete(key);
        }
        catch (OperationFailedException ex)
        {
            // handle exception
        }
 
 
See Also