ehcache2.5的源码分析 - 缓存失效机制

ehcache2.5的源码分析 ---- 缓存失效机制
2.5的算法变了,清超出的缓存的代码在这里:

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));
                            }
                        }


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);
            }
        }
    }
其实外国人写的代码也就那样,也很乱。