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);
For Adding item in a cache asynchronously
// Add Item to Cache asynchronously
_cache.addAsync(String key, CacheItem item, DSWriteOption dsWriteOption, DataSourceItemsAddedCallback onSourceItemAdded);
Thread.sleep(1000);
Object object_Customer = _cache.get("Customer:David:100");
Customer customerInformation = (Customer)object_Customer;
System.out.println("Customer ID: " + customerInformation.customerID);
System.out.println("Name: " + customerInformation.name);
System.out.println("City: " + customerInformation.getCity());
System.out.println("Contact Number: " + customerInformation.getContactNumber());
System.out.println("Order placed: " + customerInformation.isOrderInProcess());
For Updating item in a cache asynchronously
// Update Item to Cache asynchronously
_cache.insertAsync((String key, Object value, AsyncItemUpdatedCallback asyncItemUpdatedCallback,
String group, String subGroup);
Thread.sleep(1000);
Object object_Customer = _cache.get("Customer:David:100");
Customer customerInformation = (Customer)object_Customer;
System.out.println("Customer ID: " + customerInformation.customerID);
System.out.println("Name: " + customerInformation.name);
System.out.println("City: " + customerInformation.getCity());
System.out.println("Contact Number: " + customerInformation.getContactNumber());
System.out.println("Order placed: " + customerInformation.isOrderInProcess());
For Removing item from a cache asynchronously
// Remove Item from Cache asynchronously
_cache.removeAsync(String key, AsyncItemRemovedCallback asyncItemRemovedCallback, DSWriteOption dsWriteOption, DataSourceItemsRemovedCallback onDataSourceItemRemoved);
For Clearing cache asynchronously
// Clear Cache asynchronously
_cache.clearAsync(DSWriteOption dsWriteOption, AsyncCacheClearedCallback onAsyncCacheCleared, DataSourceClearedCallback onDataSourceCleared);