@Test public void testSetMaxCacheSize() { final long startSize = 1100; final long newSize = 5000; final long smallSize = 1000; AbstractCacheWrapper uut = new AbstractCacheWrapper(entries, storageAll, startSize, predicate -> true); assertEquals(startSize, uut.getMaxCacheSize()); uut.cacheData(c0); assertTrue(uut.dataIsInCache(c0.getId())); assertEquals(startSize, uut.getMaxCacheSize()); assertTrue(uut.setMaxCacheSize(newSize)); assertEquals(newSize, uut.getMaxCacheSize()); uut.cacheData(c1); assertTrue(uut.dataIsInCache(c0.getId())); assertTrue(uut.dataIsInCache(c1.getId())); assertTrue(uut.setMaxCacheSize(smallSize)); assertEquals(smallSize, uut.getMaxCacheSize()); assertFalse(uut.dataIsInCache(c0.getId())); assertFalse(uut.dataIsInCache(c1.getId())); }
@Override public boolean setMaxCacheSize(long maxCacheSize) { if (maxCacheSize <= 0) { log.error("The provided cache size is negative. Must be positive."); throw new IllegalArgumentException("The provided cache size is negative. Must be positive."); } lock.writeLock().lock(); try { this.maxCacheSize = maxCacheSize; while (getFreeSpace() < 0) { removeEntryByCachingStrategy(); } } finally { lock.writeLock().unlock(); } return true; }
AbstractCache implements IDataCache<T> { @Override public boolean setMaxCacheSize(long maxCacheSize) { if (maxCacheSize <= 0) { log.error("The provided cache size is negative. Must be positive."); throw new IllegalArgumentException("The provided cache size is negative. Must be positive."); } lock.writeLock().lock(); try { this.maxCacheSize = maxCacheSize; while (getFreeSpace() < 0) { removeEntryByCachingStrategy(); } } finally { lock.writeLock().unlock(); } return true; } }
AbstractCache implements IDataCache<T> { @Override public boolean setMaxCacheSize(long maxCacheSize) { if (maxCacheSize <= 0) { log.error("The provided cache size is negative. Must be positive."); throw new IllegalArgumentException("The provided cache size is negative. Must be positive."); } lock.writeLock().lock(); try { this.maxCacheSize = maxCacheSize; while (getFreeSpace() < 0) { removeEntryByCachingStrategy(); } } finally { lock.writeLock().unlock(); } return true; } AbstractCache(S entries, IDataStorage<T> cachedStorage, long maxCacheSize,
      Predicate<T> cachingRule); }
AbstractCache implements IDataCache<T> { @Override public boolean setMaxCacheSize(long maxCacheSize) { if (maxCacheSize <= 0) { log.error("The provided cache size is negative. Must be positive."); throw new IllegalArgumentException("The provided cache size is negative. Must be positive."); } lock.writeLock().lock(); try { this.maxCacheSize = maxCacheSize; while (getFreeSpace() < 0) { removeEntryByCachingStrategy(); } } finally { lock.writeLock().unlock(); } return true; } AbstractCache(S entries, IDataStorage<T> cachedStorage, long maxCacheSize,
      Predicate<T> cachingRule); @Override long getMaxCacheSize(); @Override boolean setMaxCacheSize(long maxCacheSize); @Override long getCurrentCacheSize(); @Override long getFreeSpace(); @Override boolean hasStorageFor(long size); @Override void cacheData(T data); @Override void uncacheData(T data); @Override boolean dataIsCachable(T data); @Override boolean dataIsInCache(long id); @Override void clearCache(); @Override boolean dataExists(long id); @Override T loadData(long id); @Override boolean saveData(T data); @Override boolean dataIsStorable(T data); @Override boolean deleteData(T data); }
AbstractCache implements IDataCache<T> { @Override public boolean setMaxCacheSize(long maxCacheSize) { if (maxCacheSize <= 0) { log.error("The provided cache size is negative. Must be positive."); throw new IllegalArgumentException("The provided cache size is negative. Must be positive."); } lock.writeLock().lock(); try { this.maxCacheSize = maxCacheSize; while (getFreeSpace() < 0) { removeEntryByCachingStrategy(); } } finally { lock.writeLock().unlock(); } return true; } AbstractCache(S entries, IDataStorage<T> cachedStorage, long maxCacheSize,
      Predicate<T> cachingRule); @Override long getMaxCacheSize(); @Override boolean setMaxCacheSize(long maxCacheSize); @Override long getCurrentCacheSize(); @Override long getFreeSpace(); @Override boolean hasStorageFor(long size); @Override void cacheData(T data); @Override void uncacheData(T data); @Override boolean dataIsCachable(T data); @Override boolean dataIsInCache(long id); @Override void clearCache(); @Override boolean dataExists(long id); @Override T loadData(long id); @Override boolean saveData(T data); @Override boolean dataIsStorable(T data); @Override boolean deleteData(T data);  }