更正键注释以缓存列表中的项目,而不是整个列表 [英] Correct key annotation for caching on items in a list rather then the whole list

查看:73
本文介绍了更正键注释以缓存列表中的项目,而不是整个列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下面的代码存在的问题是基于列表而不是列表中的每个项目进行缓存。

My problem with the code below is that is caches based on the list instead of per items in the list.

因此,如果我将此方法发送的列表中包含2它们都被缓存了,而不是删除其中一个项目而再次调用该方法,它应该从缓存中读取,但是却看到列表已更改,因此运行该方法而不是使用缓存。

so if I send this method a list with 2 items, they both get cached, than make another call to the method with one of those items removed, it should read from the cache but instead it sees that the list has changed and so runs the method rather then using the cache.

什么是正确的注释,以便其缓存在单个项目而不是整个列表上?

What would be the correct annotation so that it caches on the individual items instead of the whole list?

@Override
@Cacheable(value = "cacheName")
public Properties retrieveProperties(List<String> testList) {


推荐答案

无法使用Spring Caching注释来完成您想要的事情。

There is no way to do what you want using Spring Caching annotations.

此外,操作的语义是什么?

Also, what would be the semantics of the operation?


  • 属性内容由 List 内容驱动?

  • 还是其他?

  • The Properties content is driven by the List content?
  • or something else?

又像Spring提供的那样,泛型抽象如何能够涵盖这些特定用例?

And how could a generic abstraction such as the one offered by Spring be able to cover these specific use cases?

因此,简而言之,您将必须针对这种特定用例编写自己的缓存逻辑。

So in short, you will have to write your own caching logic for such a specific use case.

这篇关于更正键注释以缓存列表中的项目,而不是整个列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆