清超出的缓存的代码在这里:
net.sf.ehcache.store.chm.SelectableConcurrentHashMap
第五百行
int runs = Math.min(MAX_EVICTION, SelectableConcurrentHashMap.this.quickSize() - (int) SelectableConcurrentHashMap.this.maxSize);
while (runs-- > 0) {
Element evict = nextExpiredOrToEvict(value);
if (evict != null) {
evicted[runs] = (remove(evict.getKey(), hash(evict.getKey().hashCode()), null));
}
}
这里跟2.4一样,也是随机取三十个对比,然后清理。
net.sf.ehcache.store.MemoryStore
private void checkCapacity(final Element elementJustAdded) {
if (maximumSize > 0 && !isClockEviction()) {
int evict = Math.min(map.quickSize() - maximumSize, MAX_EVICTION_RATIO);
for (int i = 0; i < evict; i++) {
removeElementChosenByEvictionPolicy(elementJustAdded);
}
}
}
其实外国人写的代码也就那样,也很乱。
net.sf.ehcache.store.chm.SelectableConcurrentHashMap
第五百行
int runs = Math.min(MAX_EVICTION, SelectableConcurrentHashMap.this.quickSize() - (int) SelectableConcurrentHashMap.this.maxSize);
while (runs-- > 0) {
Element evict = nextExpiredOrToEvict(value);
if (evict != null) {
evicted[runs] = (remove(evict.getKey(), hash(evict.getKey().hashCode()), null));
}
}
这里跟2.4一样,也是随机取三十个对比,然后清理。
net.sf.ehcache.store.MemoryStore
private void checkCapacity(final Element elementJustAdded) {
if (maximumSize > 0 && !isClockEviction()) {
int evict = Math.min(map.quickSize() - maximumSize, MAX_EVICTION_RATIO);
for (int i = 0; i < evict; i++) {
removeElementChosenByEvictionPolicy(elementJustAdded);
}
}
}
其实外国人写的代码也就那样,也很乱。