为什么番石榴缓存支持 weakKeys() 和 weakValues()

why guava cache support weakKeys() AND weakValues()

Guava CacheBuilder 同时支持 weakKeys() 和 weakValues()。 但是,如果收集了值,为什么我们还要将键保留在缓存中? 那么如果我们只使用 weakKeys() 就足够了?

不是weakKeys是"collect the keys but keep the values,"还是weakValues 表示 "collect the values but keep the keys."

weakKeys 做的是说,"when there are no longer any strong references to the key, collect the entire entry." weakValues 做的是说,"when there are no longer any strong references to the value, collect the entire entry." 所以当你同时使用两者时,当 [=18] 时收集整个条目=] 键或值没有指向它的强引用。