StringCache { public String get(String path) { if (cache.size() >= CACHE_SIZE && !cache.containsKey(path)) { LOG.debug("Cache size too big. Revise your mount setup."); return path; } return cache.computeIfAbsent(path, (k) -> { if (monitor != null) { monitor.onAddStringCacheEntry(); } return path; }); }  String get(String path); StringCache withMonitor(CompositeNodeStoreMonitor monitor);  }
@Test public void testCache() { StringCache cache = new StringCache(); StringBuilder b = new StringBuilder("abc").append("xyz"); String s1 = b.toString(); String s2 = b.toString(); String s3 = b.toString(); Assert.assertNotSame(s1, s2); Assert.assertNotSame(s2, s3); Assert.assertNotSame(s1, s3); String c1 = cache.get(s1); String c2 = cache.get(s2); String c3 = cache.get(s3); Assert.assertSame(c1, c2); Assert.assertSame(c2, c3); Assert.assertSame(c1, c3); }