NCache 4.4 - Online Documentation

Remove Data from Cache

 
Deleting item(s) from the cache is also considered as one of the basic operations. NCache primarily provides two methods to delete an item from cache. These are:
 
  • Delete
  • Remove
 
Difference between Delete and Remove methods
 
delete
remove
 
Returns nothing after deletion.
Deletes data from the cache and returns deleted data to the application.
 
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