Alachisoft NCache 4.1 - Online Documentation

Delete 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 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. 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.
     
    import java.io.Serializable;
    public class Customer implements Serializable
    {
    ......
    }
     
  4. Now insert the following code in the 'Main' of the project.
     
    Cache _cache = NCache.initializeCache("myCache");
    _cache.clear();
     
    Customer customer = new Customer();
    customer.name = "David";
    customer.customerID = 1001;
    customer.setCity("London");
    customer.setContactNumber("+44-xxx-xxxx-xxxx");
    customer.setOrderInProcess(true);
     
    // Add Item to Cache
          _cache.add("Customer:David:1001", customer);
     
    // Delete the above Item from the Cache
    _cache.delete("Customer:David:1001");
     
     
  5. Start the Local Cache 'myCache'.
  6. Run the project.
 
 
 
See Also

 
Copyright © 2005-2012 Alachisoft. All rights reserved.