0
請這個魔法幫助我觀察這裏:番石榴緩存魔法命中
Map<String, RenditionMeta> map = cache.asMap();
System.out.println("Before iterating: " + map.containsKey(objectId));
for(String s : map.keySet()) {
if(s.equals(objectId)) {
System.out.println(s + " equals " + objectId + ":" + s.equals(objectId) + "-" + map.containsKey(objectId));
System.out.println(objectId.hashCode());
System.out.println(s.hashCode());
}
}
輸出:
Before iterating: false
09009e5d805f6b0b equals 09009e5d805f6b0b:true-false
1453886923
1453886923
有人能解釋如何「真假」是可能的上方?
緩存當你使用弱密鑰選項番石榴緩存使用鑰匙你觀察到的行爲,因此身份平等定義爲
this.cache = CacheBuilder.newBuilder()
.concurrencyLevel(4)
.weakKeys()
.maximumSize(10000)
.expireAfterWrite(10, TimeUnit.MINUTES)
.build();
返回的地圖不是緩存的副本。這是緩存的實時視圖。因此,在迭代的那一刻和調用containsKey()的那一刻之間,鍵將從緩存中刪除。 –
我想過了。請參閱添加的行。問題:地圖中的值如何顯示? – user431529