@Override public void add(T e) { cacheMap.put(e, theOnlyValue) ; }
@Override public Value put(Key key, Value t) { Value v = cache.put(key, t) ; if ( v == null ) // Was not there before cacheEntries.getAndIncrement() ; return v ; }
public void addCacheModel(String uri, Model m) { if ( isCachingModels() ) modelCache.put(uri, m) ; }
protected void addToCache(Model model) { // Assume MRSW - no synchronized needed. cache.put(model.getGraph(), model) ; }
@Override synchronized public void overwrite(Block block) { Long id = block.getId() ; // It can be a read block (by the transaction), now being written for real (enacting a transaction). super.overwrite(block) ; // Keep read cache up-to-date. // Must at least expel the read block (which is not the overwrite block). readCache.put(id, block) ; }
@Override synchronized public void overwrite(Block block) { Long id = block.getId() ; // It can be a read block (by the transaction), now being written for // real (enacting a transaction). super.overwrite(block) ; // Keep read cache up-to-date. // Must at least expel the read block (which is not the overwrite // block). readCache.put(id, block) ; }
private void writeCache(Block block) { Long id = block.getId() ; log("WriteCache : %d", id) ; // Should not be in the read cache due to a getWrite earlier. if ( readCache.containsKey(id) ) log.warn("write: Block in the read cache") ; if ( writeCache != null ) { writeCache.put(id, block) ; return ; } }
private void writeCache(Block block) { Long id = block.getId() ; log("WriteCache : %d", id) ; // Should not be in the read cache due to a getWrite earlier. if ( readCache.containsKey(id) ) log.warn("write: Block in the read cache") ; if ( writeCache != null ) { writeCache.put(id, block) ; return ; } }
private void writeCache(Block block) { Long id = block.getId() ; log("WriteCache : %d", id) ; // Should not be in the read cache due to a getWrite earlier. if ( readCache.containsKey(id) ) log.warn("write: Block in the read cache") ; if ( writeCache != null ) { writeCache.put(id, block) ; return ; } }
@Override synchronized public Block promote(Block block) { Long id = block.getId() ; readCache.remove(id) ; Block block2 = super.promote(block) ; if ( writeCache != null ) writeCache.put(id, block2) ; return block ; }
@Override synchronized public Block promote(Block block) { Long id = block.getId() ; readCache.remove(id) ; Block block2 = super.promote(block) ; if ( writeCache != null ) writeCache.put(id, block2) ; return block ; }
@Override public IRI resolveSilent(String uriStr) { if (resolvedIRIs != null && resolvedIRIs.containsKey(uriStr)) return resolvedIRIs.get(uriStr) ; IRI iri = iriFactory.create(uriStr) ; if (resolvedIRIs != null) resolvedIRIs.put(uriStr, iri) ; return iri ; }
@Override synchronized public Block promote(Block block) { Long id = block.getId() ; readCache.remove(id) ; Block block2 = super.promote(block) ; if ( writeCache != null ) writeCache.put(id, block2) ; return block ; }
public final boolean checkURI(Node node, long line, long col) { if ( cache != null && cache.containsKey(node) ) return true ; IRI iri = iriFactory.create(node.getURI()) ; // always works - no exceptions. boolean b = checkIRI(iri, line, col) ; // If OK, put in cache. if ( cache != null && b ) cache.put(node, iri) ; return b ; }
public final boolean checkURI(Node node, long line, long col) { if ( cache != null && cache.containsKey(node) ) return true ; IRI iri = iriFactory.create(node.getURI()); // always works - no exceptions. boolean b = checkIRI(iri, line, col) ; // If OK, put in cache. if ( cache != null && b ) cache.put(node, iri) ; return b ; }
@Test public void testReplace() { final Integer key = 1 ; final String value1 = "A" ; final String value2 = "B" ; final Cache<Integer, Object> testCache = new CacheSimple<>(5); testCache.put(key, value1); testCache.put(key, value2); assertEquals("Wrong size", 1, testCache.size()) ; assertEquals("Wrong slot contents", value2, testCache.getIfPresent(key)) ; }
@Test public void cache_04() { cache.clear() ; cache.put(7, 77) ; List<Integer> x = Iter.toList(cache.keys()) ; assertEquals(1, x.size()) ; assertEquals(Integer.valueOf(7), x.get(0)) ; }
@Test public void cache_01() { Integer x = cache.getIfPresent(7) ; cache.put(7, 7) ; assertEquals(1, cache.size()) ; assertNull(x) ; assertTrue(cache.containsKey(7)) ; assertEquals(Integer.valueOf(7), cache.getIfPresent(7)) ; }
@Test public void cache_05() { cache.clear() ; cache.put(7, 77) ; cache.clear() ; assertEquals(0, cache.size()) ; assertTrue(cache.isEmpty()) ; } }