@Test public void testCountBasedLimitSetToNoLimit() { configuration.setOverflowToOffHeap(false); configuration.setMaxEntriesLocalHeap(0); assertThat(loader.isInMemoryLimitReached(cache, 0), is(false)); assertThat(loader.isInMemoryLimitReached(cache, Integer.MAX_VALUE), is(true)); }
protected boolean isInMemoryLimitReached(final Ehcache cache, final int loadedElements) { long maxBytesInMem; long maxElementsInMem; final boolean overflowToOffHeap = cache.getCacheConfiguration().isOverflowToOffHeap(); maxElementsInMem = cache.getCacheConfiguration().getMaxEntriesLocalHeap() == 0 ? Integer.MAX_VALUE : cache.getCacheConfiguration().getMaxEntriesLocalHeap(); if (overflowToOffHeap) { maxBytesInMem = cache.getCacheConfiguration().getMaxBytesLocalOffHeap(); } else { maxBytesInMem = cache.getCacheConfiguration().getMaxBytesLocalHeap(); } if (maxBytesInMem != 0) { final long inMemoryCount = overflowToOffHeap ? cache.getStatistics().getLocalOffHeapSize() : cache.getStatistics().getLocalHeapSize(); if (inMemoryCount == 0L) { return false; } else { final long inMemorySizeInBytes = overflowToOffHeap ? cache.getStatistics().getLocalOffHeapSizeInBytes() : cache.getStatistics() .getLocalHeapSizeInBytes(); final long avgSize = inMemorySizeInBytes / inMemoryCount; return inMemorySizeInBytes + (avgSize * 2) >= maxBytesInMem; } } else { return loadedElements >= maxElementsInMem; } }
MemoryLimitedCacheLoader implements BootstrapCacheLoader, Cloneable { protected boolean isInMemoryLimitReached(final Ehcache cache, final int loadedElements) { long maxBytesInMem; long maxElementsInMem; final boolean overflowToOffHeap = cache.getCacheConfiguration().isOverflowToOffHeap(); maxElementsInMem = cache.getCacheConfiguration().getMaxEntriesLocalHeap() == 0 ? Integer.MAX_VALUE : cache.getCacheConfiguration().getMaxEntriesLocalHeap(); if (overflowToOffHeap) { maxBytesInMem = cache.getCacheConfiguration().getMaxBytesLocalOffHeap(); } else { maxBytesInMem = cache.getCacheConfiguration().getMaxBytesLocalHeap(); } if (maxBytesInMem != 0) { final long inMemoryCount = overflowToOffHeap ? cache.getStatistics().getLocalOffHeapSize() : cache.getStatistics().getLocalHeapSize(); if (inMemoryCount == 0L) { return false; } else { final long inMemorySizeInBytes = overflowToOffHeap ? cache.getStatistics().getLocalOffHeapSizeInBytes() : cache.getStatistics() .getLocalHeapSizeInBytes(); final long avgSize = inMemorySizeInBytes / inMemoryCount; return inMemorySizeInBytes + (avgSize * 2) >= maxBytesInMem; } } else { return loadedElements >= maxElementsInMem; } } }
MemoryLimitedCacheLoader implements BootstrapCacheLoader, Cloneable { protected boolean isInMemoryLimitReached(final Ehcache cache, final int loadedElements) { long maxBytesInMem; long maxElementsInMem; final boolean overflowToOffHeap = cache.getCacheConfiguration().isOverflowToOffHeap(); maxElementsInMem = cache.getCacheConfiguration().getMaxEntriesLocalHeap() == 0 ? Integer.MAX_VALUE : cache.getCacheConfiguration().getMaxEntriesLocalHeap(); if (overflowToOffHeap) { maxBytesInMem = cache.getCacheConfiguration().getMaxBytesLocalOffHeap(); } else { maxBytesInMem = cache.getCacheConfiguration().getMaxBytesLocalHeap(); } if (maxBytesInMem != 0) { final long inMemoryCount = overflowToOffHeap ? cache.getStatistics().getLocalOffHeapSize() : cache.getStatistics().getLocalHeapSize(); if (inMemoryCount == 0L) { return false; } else { final long inMemorySizeInBytes = overflowToOffHeap ? cache.getStatistics().getLocalOffHeapSizeInBytes() : cache.getStatistics() .getLocalHeapSizeInBytes(); final long avgSize = inMemorySizeInBytes / inMemoryCount; return inMemorySizeInBytes + (avgSize * 2) >= maxBytesInMem; } } else { return loadedElements >= maxElementsInMem; } }  }
MemoryLimitedCacheLoader implements BootstrapCacheLoader, Cloneable { protected boolean isInMemoryLimitReached(final Ehcache cache, final int loadedElements) { long maxBytesInMem; long maxElementsInMem; final boolean overflowToOffHeap = cache.getCacheConfiguration().isOverflowToOffHeap(); maxElementsInMem = cache.getCacheConfiguration().getMaxEntriesLocalHeap() == 0 ? Integer.MAX_VALUE : cache.getCacheConfiguration().getMaxEntriesLocalHeap(); if (overflowToOffHeap) { maxBytesInMem = cache.getCacheConfiguration().getMaxBytesLocalOffHeap(); } else { maxBytesInMem = cache.getCacheConfiguration().getMaxBytesLocalHeap(); } if (maxBytesInMem != 0) { final long inMemoryCount = overflowToOffHeap ? cache.getStatistics().getLocalOffHeapSize() : cache.getStatistics().getLocalHeapSize(); if (inMemoryCount == 0L) { return false; } else { final long inMemorySizeInBytes = overflowToOffHeap ? cache.getStatistics().getLocalOffHeapSizeInBytes() : cache.getStatistics() .getLocalHeapSizeInBytes(); final long avgSize = inMemorySizeInBytes / inMemoryCount; return inMemorySizeInBytes + (avgSize * 2) >= maxBytesInMem; } } else { return loadedElements >= maxElementsInMem; } }  @Override Object clone(); }
MemoryLimitedCacheLoader implements BootstrapCacheLoader, Cloneable { protected boolean isInMemoryLimitReached(final Ehcache cache, final int loadedElements) { long maxBytesInMem; long maxElementsInMem; final boolean overflowToOffHeap = cache.getCacheConfiguration().isOverflowToOffHeap(); maxElementsInMem = cache.getCacheConfiguration().getMaxEntriesLocalHeap() == 0 ? Integer.MAX_VALUE : cache.getCacheConfiguration().getMaxEntriesLocalHeap(); if (overflowToOffHeap) { maxBytesInMem = cache.getCacheConfiguration().getMaxBytesLocalOffHeap(); } else { maxBytesInMem = cache.getCacheConfiguration().getMaxBytesLocalHeap(); } if (maxBytesInMem != 0) { final long inMemoryCount = overflowToOffHeap ? cache.getStatistics().getLocalOffHeapSize() : cache.getStatistics().getLocalHeapSize(); if (inMemoryCount == 0L) { return false; } else { final long inMemorySizeInBytes = overflowToOffHeap ? cache.getStatistics().getLocalOffHeapSizeInBytes() : cache.getStatistics() .getLocalHeapSizeInBytes(); final long avgSize = inMemorySizeInBytes / inMemoryCount; return inMemorySizeInBytes + (avgSize * 2) >= maxBytesInMem; } } else { return loadedElements >= maxElementsInMem; } }  @Override Object clone();  }