NCache 4.6 - 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.
       To utilize the API, include the following namespace in your application: 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.
  • Create a new Class named 'Customer' in your already created Test Application.
  • Insert the following code in the 'Customer' class.
class Customer
  • Now insert the following code in the 'Main' of the project:
static void Main( string [] args)
Cache _cache = NCache.InitializeCache("myCache");
Customer customer = new Customer (); = "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
  • Start the Local Cache 'myCache'.
  • Run the project.
See Also