@Test public void testLRUFileCache() throws Exception { LRUFileCache cache = new LRUFileCache(dir, 100, 9999, 1); cache.setClearOldEntriesIntervalMillis(0); assertEquals(0, cache.getSize()); assertEquals(0, getDirSize()); assertEquals(0, cache.getNumberOfItems()); byte[] buf = new byte[30]; cache.putFile("1", new ByteArrayInputStream(buf)); assertEquals(1, cache.getNumberOfItems()); assertEquals(30, cache.getSize()); assertEquals(30, getDirSize()); assertTrue(new File(dir, "1").exists()); Thread.sleep(2000); cache.putFile("2", new ByteArrayInputStream(buf)); assertEquals(2, cache.getNumberOfItems()); assertEquals(60, cache.getSize()); assertEquals(60, getDirSize()); assertTrue(new File(dir, "1").exists()); assertTrue(new File(dir, "2").exists()); Thread.sleep(2000); cache.putFile("3", new ByteArrayInputStream(buf)); assertEquals(3, cache.getNumberOfItems()); assertEquals(90, cache.getSize()); assertEquals(90, getDirSize()); assertTrue(new File(dir, "1").exists()); assertTrue(new File(dir, "2").exists()); assertTrue(new File(dir, "3").exists()); Thread.sleep(2000); cache.putFile("4", new ByteArrayInputStream(buf)); assertEquals(3, cache.getNumberOfItems()); assertEquals(90, cache.getSize()); assertEquals(90, getDirSize()); assertFalse(new File(dir, "1").exists()); assertTrue(new File(dir, "2").exists()); assertTrue(new File(dir, "3").exists()); assertTrue(new File(dir, "4").exists()); buf = new byte[150]; Thread.sleep(2000); cache.putFile("5", new ByteArrayInputStream(buf)); assertEquals(1, cache.getNumberOfItems()); assertEquals(150, cache.getSize()); assertEquals(150, getDirSize()); assertFalse(new File(dir, "2").exists()); assertFalse(new File(dir, "3").exists()); assertFalse(new File(dir, "4").exists()); assertTrue(new File(dir, "5").exists()); cache.clear(); assertEquals(0, cache.getNumberOfItems()); assertEquals(0, cache.getSize()); assertEquals(0, getDirSize()); }
public LRUFileCache(File dir, long maxSize, long maxCount, long minAge) { this.dir = dir.toPath(); this.maxSize = maxSize; this.maxCount = maxCount; this.minAgeMillis = minAge * 1000; }
LRUFileCache implements FileCache { public LRUFileCache(File dir, long maxSize, long maxCount, long minAge) { this.dir = dir.toPath(); this.maxSize = maxSize; this.maxCount = maxCount; this.minAgeMillis = minAge * 1000; } }
LRUFileCache implements FileCache { public LRUFileCache(File dir, long maxSize, long maxCount, long minAge) { this.dir = dir.toPath(); this.maxSize = maxSize; this.maxCount = maxCount; this.minAgeMillis = minAge * 1000; } LRUFileCache(File dir, long maxSize, long maxCount, long minAge); }
LRUFileCache implements FileCache { public LRUFileCache(File dir, long maxSize, long maxCount, long minAge) { this.dir = dir.toPath(); this.maxSize = maxSize; this.maxCount = maxCount; this.minAgeMillis = minAge * 1000; } LRUFileCache(File dir, long maxSize, long maxCount, long minAge); void setClearOldEntriesIntervalMillis(long millis); @Override long getSize(); @Override int getNumberOfItems(); @Override void clear(); @Override File getTempFile(); @Override File putFile(String key, InputStream in); @Override File putFile(String key, File file); @Override File getFile(String key); }
LRUFileCache implements FileCache { public LRUFileCache(File dir, long maxSize, long maxCount, long minAge) { this.dir = dir.toPath(); this.maxSize = maxSize; this.maxCount = maxCount; this.minAgeMillis = minAge * 1000; } LRUFileCache(File dir, long maxSize, long maxCount, long minAge); void setClearOldEntriesIntervalMillis(long millis); @Override long getSize(); @Override int getNumberOfItems(); @Override void clear(); @Override File getTempFile(); @Override File putFile(String key, InputStream in); @Override File putFile(String key, File file); @Override File getFile(String key); static final Pattern SIMPLE_ASCII; static final long CLEAR_OLD_ENTRIES_INTERVAL_MILLIS_DEFAULT; }