Alachisoft NCache 4.1 - Online Documentation

Deleting Items

Once you have a valid cache handle, you can do the "Delete" operations on a cache. This operation has many overloads and the basic overload takes only one parameter i.e. "key" as string.
Using Delete Method
A "Delete" method will delete item(s) from the cache only if item(s) already exist in the cache. Exception will be thrown if the method is unable to delete the key from the cache.
  1. Include the following import statements in your project:
    import com.alachisoft.ncache.web.caching.*;
  2. Create a new Class named 'Customer' in your already created Test Application.
  3. Insert the following code in the 'Customer' class.
    public class Customer implements Serializable
  4. Now insert the following code in the 'Main' of the project.
    Cache _cache = NCache.initializeCache("myCache");
    Customer customer = new Customer(); = "David";
    customer.customerID = 1001;
    // Add Item to Cache
    _cache.add("Customer:David:1001", customer);
    // Delete the above Item from the Cache
  5. Start the Local Cache 'myCache'.
  6. Run the project.
See Also
Copyright © 2005-2012 Alachisoft. All rights reserved.