Distributed caches
Understand value types, namespaces, and token-based conditional operations.
Types and namespaces
DistributedCacheFactory creates DistributedCache
Asynchronous and conditional operations
Operations return Future. A get miss returns null, put overwrites unconditionally, and putIfAbsent inserts only on a miss. Renewal and conditional removal use tokens to identify writes. Tokens are not ordered fencing versions.
DistributedCacheFactory factory = new InMemoryDistributedCacheFactory();
DistributedCache<RoomState> rooms = factory.create("room", RoomState.class);
CacheEntry<RoomState> entry = rooms.put("123", state, Duration.ofSeconds(30)).join();
CacheEntry<RoomState> current = rooms.get("123").join();
rooms.renew(entry, Duration.ofSeconds(30)).whenComplete((renewed, error) -> { });
rooms.remove(entry).whenComplete((removed, error) -> { });Caching and ownership
Positive local reads are disabled by default. Account for staleness and clock skew when enabling them. Concurrent getIfAbsent computations may run more than once, so the mapping function must not block or initialize external resources.
Source reference
This guide is based on the following source or module documentation. Repository access is required.
nextrix-j/nextrix-cluster/nextrix-cluster-core/CACHE.md