分布式缓存
理解类型、命名空间与基于 token 的条件操作。
master · 1.0.0-SNAPSHOT / 2026-10-29 核对
类型与命名空间
DistributedCacheFactory 创建绑定业务命名空间与值类型的 DistributedCache
异步操作与条件写
操作返回 Future。get 缺失时返回 null;put 无条件覆盖;putIfAbsent 仅在不存在时写入。renew 与条件 remove 使用 token 检查写入身份,token 不代表有序 fencing 版本。
CACHE.md / excerpt
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) -> { });源码节选 / 请结合完整示例与环境配置阅读
缓存与所有权
本地正向读取缓存默认关闭。开启后需考虑陈旧数据与时钟偏差。getIfAbsent 的并发计算可能执行多次,mappingFunction 不应阻塞或初始化外部资源。
源码出处
本页依据下列源码或模块文档整理。访问需具备仓库权限。
nextrix-j/nextrix-cluster/nextrix-cluster-core/CACHE.md