|
Terracotta Distributed Data CacheIntroductionClustered applications with a system of record (SOR) on the backend can benefit from a distributed cache that manages certain data in memory while reducing costly application-SOR interactions. However, using a cache can introduce increased complexity to software development, integration, operation, and maintenance. The Terracotta distributed cache, implemented with the Terracotta Integration Module tim-map-evictor, takes both established and innovative approaches to the caching model. tim-map-evictor solves the performance and complexity issues by:
RequirementsThe Terracotta distributed data cache requires JDK 1.5 or greater. Structure and CharacteristicsThe Terracotta distributed cache is an interface incorporating a distributed map with standard map operations: public interface DistributedMap<K, V> { // Single item operations void put(K key, V value); V get(K key); V remove(K key); boolean containsKey(K key); // Multi item operations int size(); void clear(); Set<K> getKeys(); // For managing the background evictor thread void start(); void shutdown(); } Notable characteristics include:
Usage ExampleThe following is an example of cache that implements the Terracotta distributed cache: import org.terracotta.modules.dmap.*; import static org.terracotta.modules.dmap.DistributedMapBuilder.*; DisributedMap<String,String> map = new DistributedMapBuilder() .setMaxTTLMillis(10 * SECOND) .setMaxTTIMillis(5 * SECOND) .setConcurrency(16) .newMap(); map.start(); // start eviction thread map.put("Rabbit", "Carrots"); map.put("Dog", "Bone"); map.put("Owl", "Mouse"); // wait 3 seconds map.get("Rabbit"); // wait 2 seconds - expire Dog and Owl due to TTI assert ! map.containsKey("Dog"); assert ! map.containsKey("Owl"); assert map.containsKey("Rabbit"); // wait 5 seconds - expire Rabbit due to TTL assert ! map.containsKey("Rabbit"); Terracotta Distributed Cache in a Reference ApplicationThe [Examinator reference application] uses the Terracotta distributed cache to handle pending user registrations. This type of data has a "medium-term" lifetime which needs to be persisted long enough to give prospective registrants a chance to verify their registrations. If a registration isn't verified by the time TTL is reached, it can be evicted from the cache. Only if the registration is verified is it written to the database. The combination of Terracotta and the Terracotta distributed cache gives Examinator the following advantages:
|
Distributed Data Cache
(None)