/** * Check caches to see if we can map a NodeId to a Node. Returns null on no * cache entry. */ private Node cacheLookup(NodeId id) { if ( id2node_Cache == null ) return null ; return id2node_Cache.getIfPresent(id) ; }
/** Check caches to see if we can map a NodeId to a Node. Returns null on no cache entry. */ private Node cacheLookup(NodeId id) { if ( id2node_Cache == null ) return null ; return id2node_Cache.getIfPresent(id) ; }
public Node getNodeForNodeIdCache(NodeId id) { return id2node_Cache.getIfPresent(id) ; }
public NodeId getNodeIdForNodeCache(Node node) { return node2id_Cache.getIfPresent(node) ; }
@Override public T getIfPresent(Key key) { return cache.getIfPresent(key) ; }
@Override public T getIfPresent(Key key) { return cache.getIfPresent(key) ; }
/** Check caches to see if we can map a Node to a NodeId. Returns null on no cache entry. */ private NodeId cacheLookup(Node node) { // Remember things known (currently) not to exist. // Does not matter if notPresent is being updated elsewhere. if ( notPresent != null && notPresent.contains(node) ) return null ; if ( node2id_Cache == null ) return null ; return node2id_Cache.getIfPresent(node) ; }
/** Read out of the cache - return null if not in the cache */ public Model getFromCache(String filenameOrURI) { if ( ! isCachingModels() ) return null; return modelCache.getIfPresent(filenameOrURI) ; }
/** * Check caches to see if we can map a Node to a NodeId. Returns null on no * cache entry. */ private NodeId cacheLookup(Node node) { // Remember things known (currently) not to exist. // Does not matter if notPresent is being updated elsewhere. if ( notPresent != null && notPresent.contains(node) ) return null ; if ( node2id_Cache == null ) return null ; return node2id_Cache.getIfPresent(node) ; }
/** Implementation of getOrFill based on Cache.get and Cache.put */ public static <K,V> V getOrFill(Cache<K,V> cache, K key, Callable<V> callable) { V value = cache.getIfPresent(key) ; if ( value == null ) { try { value = callable.call() ; } catch (Exception e) { throw new AtlasException("Exception on cache fill", e) ; } if ( value != null ) cache.put(key, value) ; } return value ; }
/** Implementation of getOrFill based on Cache.get and Cache.put */ public static <K,V> V getOrFill(Cache<K,V> cache, K key, Callable<V> callable) { V value = cache.getIfPresent(key) ; if ( value == null ) { try { value = callable.call() ; } catch (Exception e) { throw new AtlasException("Exception on cache fill", e) ; } if ( value != null ) cache.put(key, value) ; } return value ; }
private void expelEntry(Long id) { Block block = writeCache.getIfPresent(id) ; if ( block == null ) { log.warn("Write cache: " + id + " expelling entry that isn't there") ; return ; } log("Expel (write cache): %d", id) ; // This pushes the block to the BlockMgr being cached. super.write(block) ; writeCache.remove(id) ; // Move it into the readCache because it's often read after writing // and the read cache is often larger. readCache.put(id, block) ; } }
private void expelEntry(Long id) { Block block = writeCache.getIfPresent(id) ; if ( block == null ) { log.warn("Write cache: "+id+" expelling entry that isn't there") ; return ; } log("Expel (write cache): %d", id) ; // This pushes the block to the BlockMgr being cached. super.write(block) ; writeCache.remove(id) ; // Move it into the readCache because it's often read after writing // and the read cache is often larger. readCache.put(id, block) ; }
private void expelEntry(Long id) { Block block = writeCache.getIfPresent(id) ; if ( block == null ) { log.warn("Write cache: " + id + " expelling entry that isn't there") ; return ; } log("Expel (write cache): %d", id) ; // This pushes the block to the BlockMgr being cached. super.write(block) ; writeCache.remove(id) ; // Move it into the readCache because it's often read after writing // and the read cache is often larger. readCache.put(id, block) ; } }
@Test public void cache_10() { Cache<Integer, String> cache = CacheFactory.createOneSlotCache() ; String str = cache.getIfPresent(1) ; assertNull(str) ; cache.put(1, "1") ; str = cache.getIfPresent(1) ; assertEquals("1", str) ; cache.put(2, "2") ; str = cache.getIfPresent(1) ; assertNull(str) ; cache.put(1, "1") ; str = cache.getIfPresent(2) ; assertNull(str) ; str = cache.getIfPresent(1) ; assertEquals("1", str) ; }
@Test public void cache_03() { cache.put(7, 7) ; Integer x1 = cache.getIfPresent(7) ; cache.put(7, 18) ; assertEquals(1, cache.size()) ; assertEquals(7, x1.intValue()) ; assertTrue(cache.containsKey(7)) ; assertEquals(Integer.valueOf(18), cache.getIfPresent(7)) ; }
@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_02() { cache.put(7, 7) ; cache.put(8, 8) ; // Not true for Cache1. if ( size > 2 ) assertEquals(2, cache.size()) ; if ( size > 2 ) assertTrue(cache.containsKey(7)) ; if ( size > 2 ) assertEquals(Integer.valueOf(7), cache.getIfPresent(7)) ; assertTrue(cache.containsKey(8)) ; assertEquals(Integer.valueOf(8), cache.getIfPresent(8)) ; }
@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 cacheGetter_2() { Cache<Integer, String> cache = CacheFactory.createCache(2) ; String str1 = cache.getOrFill(1, getter(1)) ; String str2 = cache.getOrFill(2, getter(2)) ; String str3 = cache.getOrFill(3, getter(3)) ; assertEquals("1", str1) ; assertEquals("2", str2) ; assertEquals("3", str3) ; cache.put(1, "10") ; str1 = cache.getIfPresent(1) ; assertEquals("10", str1) ; }