REDIS缓存 - 返回缓存操作的NULL键(也许您在没有调试信息的情况下使用命名参数?)

发布于 2025-01-28 02:00:23 字数 987 浏览 4 评论 0原文

我正在使用弹簧缓存进行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信息的情况下使用命名参数?)> 没有指定任何密钥,缓存具有从这两种方法返回的引导策略测试对象。

我想要的是

  1. 在缓存中拥有一份客户的副本,对输入不利。但是现在,同一对象被缓存两次
  2. ,需要使用键指定@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

  1. Have a single copy of customer in the cache, irresective of the input. But now the same object are cached twice
  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

与往事干杯 2025-02-04 02:00:23

您可以尝试使用key =“#p0”

You can try to use key ="#p0"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文