Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 如何找出cacheManager(org.springframework.cache.cacheManager)中是否存在密钥_Spring Boot_Caching_Infinispan - Fatal编程技术网

Spring boot 如何找出cacheManager(org.springframework.cache.cacheManager)中是否存在密钥

Spring boot 如何找出cacheManager(org.springframework.cache.cacheManager)中是否存在密钥,spring-boot,caching,infinispan,Spring Boot,Caching,Infinispan,是否有办法查看cacheManager(org.springframework.cache.cacheManager)中是否存在特定密钥,因为我找不到这样做的方法,因为没有containsKey选项。如果有人能告诉我一种检查cacheManager中是否存在密钥的方法,我将不胜感激。以下是迄今为止我尝试过的几件事- Cache cache=null; for (String name : cacheManager.getCacheNames()) { cache=cacheManager

是否有办法查看cacheManager(
org.springframework.cache.cacheManager
)中是否存在特定密钥,因为我找不到这样做的方法,因为没有
containsKey
选项。如果有人能告诉我一种检查cacheManager中是否存在密钥的方法,我将不胜感激。以下是迄今为止我尝试过的几件事-

Cache cache=null;
for (String name : cacheManager.getCacheNames()) {
    cache=cacheManager.getCache(name);
    System.out.println("-------------->"+cache.get("dummyCache").get()); //this will give me null pointer exception as there is no dummyCache 
    }

我想添加if/else检查以查看缓存中是否存在
dummyCache

您只需检查
cache.get
null
返回的值即可

(我强调):

返回此缓存将指定键映射到的值,该值包含在cache.ValueWrapper中,该值也可能包含缓存的空值返回的直接空表示缓存不包含此键的映射。

所以

  • cache.get(“foo”)==null意味着:缓存中不存在键“foo”
  • cache.get(“foo”).get()

您只需检查
缓存返回的值。获取
空值的

(我强调):

返回此缓存将指定键映射到的值,该值包含在cache.ValueWrapper中,该值也可能包含缓存的空值返回的直接空表示缓存不包含此键的映射。

所以

  • cache.get(“foo”)==null意味着:缓存中不存在键“foo”
  • cache.get(“foo”).get()

因此,如果我在缓存时正确理解了这一点。get(“foo”)表示缓存中已经存在“foo”键,并且不为null,但是如果我想检查缓存中是否存在“foo”,该怎么办?回答我的问题的部分感谢您的澄清如果我在缓存时正确理解这一点。get(“foo”)表示“foo”密钥已存在于缓存中且不为空,但如果我想检查缓存中是否存在“foo”,该怎么办回答我的问题的ome谢谢您的澄清