Spring boot 如何找出cacheManager(org.springframework.cache.cacheManager)中是否存在密钥
是否有办法查看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
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谢谢您的澄清