dtcache本地jvm内的k/v缓存
dtcache 一个本地jvm内的key-value缓存,支持分布式数据更新,支持自定义过期策略
配置:
CacheItemListener cacheItemListener = new CacheItemListenerRedisImpl() { @Override public Jedis getRedis() { return redis.getResource(); } @Override public void closeRedis(Jedis jedis) { redis.returnResource(jedis); } }; CacheConfig config = new CacheConfig.Builder().cacheItemListener(cacheItemListener).build(); LocalCache.start(config);
写:
Cache cache = new LocalCache(); User user = new User(); user.setUserId("userId"); user.setUsername("username"); cache.put(user.getUserId(), user);
读:
Cache cache = new LocalCache(); User user = cache.get("userId", User.class);
删除:
Cache cache = new LocalCache(); cache.delete(User.class, "userId);
评论