REDIS缓存 - 返回缓存操作的NULL键(也许您在没有调试信息的情况下使用命名参数?)
我正在使用弹簧缓存进行REDIS。我有2种方法每个返回策略测试对象,但使用不同的参数调用,如下所示。
// @Cacheable(value = "policyTest", key = "#policyNo")
@Cacheable(value = "policyTest")
public PolicyTest getPolicyByNo(String policyNo) {
log.info("RedisServiceImpl::getPolicyByNo() fetching TestPolicy from service ...");
return new PolicyTest(policyNo, "1005", "200555");
}
// @Cacheable(value = "policyTest", key = "#policyNo")
@Cacheable(value = "policyTest")
public PolicyTest getPolicyByCustomerNo(String customerNo) {
log.info("RedisServiceImpl::getPolicyByCustomerNo() fetching TestPolicy from service ...");
return new PolicyTest("125", "1005", customerNo);
}
对于这两种方法,指定的policyno为键,但是对于返回用于缓存操作的null键的getPolicyByCustomerno(字符串custicerno)失败了(也许您在没有debug信息的情况下使用命名参数?)> 没有指定任何密钥,缓存具有从这两种方法返回的引导策略测试对象。
我想要的是
- 在缓存中拥有一份客户的副本,对输入不利。但是现在,同一对象被缓存两次
- ,需要使用键指定@cach -caching,但它会引发错误 - 返回缓存操作的null键(也许您在没有调试信息的情况下在类上使用命名参数?)
I'm using Spring Cache for Redis. I've 2 methods each returns policyTest object but are invoked with different parameters as shown below.
// @Cacheable(value = "policyTest", key = "#policyNo")
@Cacheable(value = "policyTest")
public PolicyTest getPolicyByNo(String policyNo) {
log.info("RedisServiceImpl::getPolicyByNo() fetching TestPolicy from service ...");
return new PolicyTest(policyNo, "1005", "200555");
}
// @Cacheable(value = "policyTest", key = "#policyNo")
@Cacheable(value = "policyTest")
public PolicyTest getPolicyByCustomerNo(String customerNo) {
log.info("RedisServiceImpl::getPolicyByCustomerNo() fetching TestPolicy from service ...");
return new PolicyTest("125", "1005", customerNo);
}
For both methods, specified policyNo as key, but it is failing for getPolicyByCustomerNo(String customerNo) with error Null key returned for cache operation (maybe you are using named params on classes without debug info?)
Without any key specified, the cache has dulicate PolicyTest object that are returned from both methods.
What I want is
- Have a single copy of customer in the cache, irresective of the input. But now the same object are cached twice
- want to specify @Cacheable with key, but it throws error - Null key returned for cache operation (maybe you are using named params on classes without debug info?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试使用key =“#p0”
You can try to use key ="#p0"