/** Change the state of model cache : does not clear the cache */ public void setModelCaching(boolean state) { cacheModelLoads = state ; if ( cacheModelLoads && modelCache == null ) modelCache = CacheFactory.createCache(CacheSize) ; }
private NodeTableCache(NodeTable baseTable, int nodeToIdCacheSize, int idToNodeCacheSize, int nodeMissesCacheSize) { this.baseTable = baseTable ; if ( nodeToIdCacheSize > 0 ) node2id_Cache = CacheFactory.createCache(nodeToIdCacheSize) ; if ( idToNodeCacheSize > 0 ) id2node_Cache = CacheFactory.createCache(idToNodeCacheSize) ; if ( nodeMissesCacheSize > 0 ) notPresent = CacheFactory.createCacheSet(nodeMissesCacheSize) ; }
/** Create a cache which has space for upto a certain number of objects. * Call the getter when the cache has a miss. */ public static <Key, Value> Cache<Key, Value> createCache(Getter<Key, Value> getter, int maxSize) { Cache<Key, Value> cache = createCache(0.75f, maxSize) ; return createCacheWithGetter(cache, getter) ; }
private BlockMgrCache(int readSlots, int writeSlots, final BlockMgr blockMgr) { super(blockMgr) ; // Caches are related so we can't use a Getter for cache management. if ( readSlots < -1 ) readCache = CacheFactory.createNullCache() ; else readCache = CacheFactory.createCache(readSlots) ; if ( writeSlots <= 0 ) writeCache = null ; else { writeCache = CacheFactory.createCache(writeSlots) ; writeCache.setDropHandler((id, block) -> { // We're inside a synchronized operation at this point. log("Cache spill: write block: %d", id) ; if ( block == null ) { log.warn("Write cache: " + id + " dropping an entry that isn't there") ; return ; } // Force the block to be writtern // by sending it to the wrapped BlockMgr BlockMgrCache.super.write(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) ; }
private BlockMgrCache(int readSlots, int writeSlots, final BlockMgr blockMgr) { super(blockMgr) ; // Caches are related so we can't use a Getter for cache management. if ( readSlots < -1 ) readCache = CacheFactory.createNullCache() ; else readCache = CacheFactory.createCache(readSlots) ; if ( writeSlots <= 0 ) writeCache = null ; else { writeCache = CacheFactory.createCache(writeSlots) ; writeCache.setDropHandler((id, block) -> { // We're inside a synchronized operation at this point. log("Cache spill: write block: %d", id) ; if ( block == null ) { log.warn("Write cache: " + id + " dropping an entry that isn't there") ; return ; } // Force the block to be writtern // by sending it to the wrapped BlockMgr BlockMgrCache.super.write(block) ; }) ; } }
/** Change the state of model cache : does not clear the cache */ public void setModelCaching(boolean state) { cacheModelLoads = state ; if ( cacheModelLoads && modelCache == null ) modelCache = CacheFactory.createCache(CacheSize) ; }
private BlockMgrCache(int readSlots, int writeSlots, final BlockMgr blockMgr) { super(blockMgr) ; // Caches are related so we can't use a Getter for cache management. if ( readSlots < -1 ) readCache = CacheFactory.createNullCache() ; else readCache = CacheFactory.createCache(readSlots) ; if ( writeSlots <= 0 ) writeCache = null ; else { writeCache = CacheFactory.createCache(writeSlots) ; writeCache.setDropHandler((id, block) -> { // We're inside a synchronized operation at this point. log("Cache spill: write block: %d", id) ; if (block == null) { log.warn("Write cache: " + id + " dropping an entry that isn't there") ; return ; } // Force the block to be writtern // by sending it to the wrapped BlockMgr BlockMgrCache.super.write(block) ; } ) ; } }
private NodeTableCache(NodeTable baseTable, int nodeToIdCacheSize, int idToNodeCacheSize, int nodeMissesCacheSize) { this.baseTable = baseTable ; if ( nodeToIdCacheSize > 0 ) node2id_Cache = CacheFactory.createCache(nodeToIdCacheSize) ; if ( idToNodeCacheSize > 0 ) id2node_Cache = CacheFactory.createCache(idToNodeCacheSize) ; if ( nodeMissesCacheSize > 0 ) notPresent = CacheFactory.createCacheSet(nodeMissesCacheSize) ; }
public BlankNodeAllocatorHash() { reset() ; try { mDigest = MessageDigest.getInstance(DigestAlgorithm) ; } catch (NoSuchAlgorithmException e) { throw new InternalErrorException("failed to create message digest", e) ; } Getter<String, Node> getter = new Getter<String, Node>() { @Override public Node get(String key) { return alloc(key) ; } } ; Cache<String, Node> cache1 = CacheFactory.createCache(CacheSize) ; cache = CacheFactory.createCacheWithGetter(cache1, getter) ; }
/** Create a cache which has space for up to a certain number of objects. * This is an LRU cache, or similar. * The cache returns null for a cache miss. */ public static <Key, Value> Cache<Key, Value> createCache(int maxSize) { return createCache(0.75f, maxSize) ; }
protected Cache<Graph, Model> createCache() { return CacheFactory.createCache(0.75f, 20) ; }
protected DatasetGraphCaching(int cacheSize) { if ( cacheSize <= 0 ) throw new IllegalArgumentException("Cache size is less that 1: "+cacheSize) ; namedGraphs = CacheFactory.createCache(cacheSize) ; }
/** * Create set-cache, rather than a map-cache. * The cache is thread-safe for single operations. * * @see Pool */ public static <Obj> CacheSet<Obj> createCacheSet(int size) { Cache<Obj, Object> c = createCache(size) ; return new CacheSetImpl<>(c) ; }
/** * Create set-cache, rather than a map-cache. * The cache is thread-safe for single operations. * * @see Pool */ public static <Obj> CacheSet<Obj> createCacheSet(int size) { Cache<Obj, Object> c = createCache(size) ; return new CacheSetImpl<>(c) ; }
@Override public Cache<Integer, Integer> make(int size) { return CacheFactory.createCache(size) ; } @Override
public BlankNodeAllocatorHash() { reset(); try { mDigest = MessageDigest.getInstance(DigestAlgorithm); } catch (NoSuchAlgorithmException e) { throw new InternalErrorException("failed to create message digest", e); } cache = CacheFactory.createCache(CacheSize); }
private Cache<String, ListMultimap<String, TextHit>> prepareCache(ExecutionContext execCxt) { @SuppressWarnings("unchecked") Cache<String, ListMultimap<String, TextHit>> queryCache = (Cache<String, ListMultimap<String, TextHit>>) execCxt.getContext().get(cacheSymbol); if (queryCache == null) { /* doesn't yet exist, need to create it */ queryCache = CacheFactory.createCache(CACHE_SIZE); execCxt.getContext().put(cacheSymbol, queryCache); } return queryCache; }
private Cache<String, ListMultimap<String, TextHit>> prepareCache(ExecutionContext execCxt) { @SuppressWarnings("unchecked") Cache<String, ListMultimap<String, TextHit>> queryCache = (Cache<String, ListMultimap<String, TextHit>>) execCxt.getContext().get(cacheSymbol); if (queryCache == null) { /* doesn't yet exist, need to create it */ queryCache = CacheFactory.createCache(CACHE_SIZE); execCxt.getContext().put(cacheSymbol, queryCache); } return queryCache; }
@Test public void cacheGetter_1() { Cache<Integer, String> cache = CacheFactory.createCache(2) ; String str = cache.getOrFill(1, getter(1)) ; assertEquals("1", str) ; }