Search code examples
cachingehcachelru

Why Ehcache 2.8.8 ignore my maxBytesLocalHeap parameter when using -Dnet.sf.ehcache.use.classic.lru=true


I'm using Ehcache 2.8.8's LRU policy in my webapp, when there is no -Dnet.sf.ehcache.use.classic.lru=true Ehcache respects my maxBytesLocalHeap parameter; but it doesn't do so when the system property is set.

In Class Cache:

if (useClassicLru  && onfiguration.getMemoryStoreEvictionPolicy().
equals(MemoryStoreEvictionPolicy.LRU)) {
    Store disk = createDiskStore();
    store = new LegacyStoreWrapper(new LruMemoryStore(this, disk),  
            disk, registeredEventListeners, configuration);
} else {
    if (configuration.isOverflowToDisk()) {
         store = DiskStore.createCacheStore(this, onHeapPool, 
                 onDiskPool);
    } else {
         store = MemoryStore.create(this, onHeapPool);
    }
}

And in Class LruMemoryStore:

public LruMemoryStore(Ehcache cache, Store diskStore) {
    status = Status.STATUS_UNINITIALISED;
    this.maximumSize = 
        cache.getCacheConfiguration().getMaxEntriesLocalHeap();
    this.cachePinned =  
        determineCachePinned(cache.getCacheConfiguration());
    this.elementPinningEnabled = 
        !cache.getCacheConfiguration().isOverflowToOffHeap();
    this.cache = cache;
    this.diskStore = diskStore;
    if (cache.getCacheConfiguration().isOverflowToDisk()) {
        evictionObserver = null;
    } else {
        evictionObserver = 
           StatisticBuilder.operation(EvictionOutcome.class).
           named("eviction").of(this).build();
    }
    map = new SpoolingLinkedHashMap();
    status = Status.STATUS_ALIVE;
    copyStrategyHandler = MemoryStore.getCopyStrategyHandler(cache);
}

So I guess only MaxEntriesLocalHeap has effect?

Is it possible to set it as jvm system property?


Solution

  • When you explicitly request classic LRU you actually get an older version of internal code that was preserved because some users depend on its behaviour.

    This means that you are effectively not able to use features introduced after this, including sizing the heap tier in bytes.

    So you are right, only maxEntriesLocalHeap will allow you to size the heap tier. And this cannot be set via a system property.