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.
-
Create a new Class named 'Customer' in your already created Test Application.
-
Insert the following code in the 'Customer' class.
[Serializable]
class Customer
{
...
}
-
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");
}
-
Start the Local Cache 'myCache'.
-
Run the project.
See Also