NCache 4.4 - Online Documentation

Deleting Items

 
Once you have a valid cache handle, you can perform "Delete" operations on cache. This operation has many overloads and the basic overload takes only one parameter i.e. "key" as string.
 
Include the following namespace in your project:
 
using Alachisoft.NCache.Web.Caching;
 
Using Delete Method
 
A "Delete" method will delete item from the cache only if that item already exist in the cache. Exception will be thrown if the method is unable to delete the key from the cache.
 
  1. Create a new Class named 'Customer' in your already created Test Application.
  2. Insert the following code in the 'Customer' class.
     
    [Serializable]
    class Customer
    {
        ...
    }
     
  3. Now insert the following code in the 'Main' of the project:
     
    static void Main( string [] args)
    {
    Cache _cache = NCache.InitializeCache("myCache");
    _cache.Clear();
     
    Customer customer = new Customer ();
    customer.name = "David" ;
    customer.customerID = 1001;
    customer.City = "London" ;
    customer.ContactNumber = "+44-xxx-xxxx-xxxx" ;
    customer.IsOrderInProcess = true ;
     
    // Add Item to the Cache
    _cache.Add("Customer:David:1001", customer);
     
    // Delete the above Item from the Cache
    _cache.Delete("Customer:David:1001");
     
    }
     
  4. Start the Local Cache 'myCache'.
  5. Run the project.
 
 
See Also