我想根据用户的用户名缓存一些数据,代码如下
@CachePut(key = "#user.userName", value = "loginList")
public String generateToken(User user) {
HashMap<String, Object> map = new HashMap<>();
map.put("userName", user.getUserName());
map.put("roles", user.getUroles());
String jwt = Jwts.builder()
.setClaims(map)
.setExpiration(new Date(System.currentTimeMillis() + EXPIRATION_TIME))
.signWith(SignatureAlgorithm.HS256, SECRET)
.compact();
return TOKEN_PREFIX + jwt;
}
例如对于某个用户名是testid2的用户来说,他在cache中的key应该是testid2,但实际上是loginList::testid2,也就是说,redis还把缓存的名字加在了前面,我就不是很懂了,那这样@Cachable的key属性的意义几乎没有,因为还是不能完全自定义key,请问有什么方法可以把这个key的前缀去掉呢?