对于springboot中基于方法的缓存Caching来说,我们直接以声明的方式添加,删除这些缓存,而它们在redis这种持久化产品中,通过value::key的方法组成一个redis.key,在业务方法中,可以通过这种key来手动获取它们。

  • 注解声明
	@CacheEvict(value = CacheConstants.USER_DETAILS, key = "#sysUser.username")
	public Boolean removeUserById(SysUser sysUser) {
		sysUserRoleMapper.deleteByUserId(sysUser.getUserId());
		this.removeById(sysUser.getUserId());
		return Boolean.TRUE;
	}

  • 业务代码中获取
Cache cache = cacheManager.getCache(CacheConstants.USER_DETAILS);
if (cache != null && cache.get(username) != null) {
  return (PigUser) cache.get(username).get();
}
  • redis中的存储
内容来源于网络如有侵权请私信删除

文章来源: 博客园

原文链接: https://www.cnblogs.com/lori/p/16673580.html

你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!