Alachisoft NCache 4.1 - Online Documentation

Cache Sync Dependency

 
Cache sync dependency provides a way to synchronize two caches, so an item updated or removed from one cache has same affect in synchronized cache. For example, you can have a Local Cache that keeps items frequently used by application and a Clustered Cache that keeps larger number of items being shared with other applications. And, your local items are kept synchronized with the clustered cache so you never have any data integrity problems while improving your app performance even further.
Add the following import statement in your project:
 
import com.alachisoft.ncache.web.caching.*;
import com.alachisoft.ncache.runtime.dependencies.*;
 
Following code snippet shows how CacheSyncDependency can be utilized:
 
 
Cache cache1 = NCache.initializeCache("myReplicatedCache");
Cache cache2 = NCache.initializeCache("myCache");
cache1.clear();
cache2.clear();
 
cache1.add("Customer:David:1001", "Value1");
 
// Creating CacheItem, with CacheSyncDependency assigned
CacheItem cItem = new CacheItem("Value1");
CacheSyncDependency cdb = new CacheSyncDependency("myReplicatedCache", "Customer:David:1001");
cItem.setCacheSyncDependency(cdb);
 
cache2.add("Customer:Alex:1002", cItem);
 
// Now whenever 'Customer:David:1001' in myReplicatedCache is changed it will be updated in myCache against Key: "Customer:Alex:1002"
System.out.println("Updating Value of Customer:David:1001 in myReplicatedCache to 'UpdatedValue-Check' ");
 
cache1.insert("Customer:David:1001", "UpdatedValue-Check");
 
// The value of key Customer:Alex:1002 will be updated automatically
System.out.println("Key Customer:Alex:1002 Updated with Value: " + cache.get("Customer:Alex:1002").toString());
 
 
See Also
 
Copyright © 2005-2012 Alachisoft. All rights reserved.