Refine search
@Override public V put(K key, V value) throws CacheException { final V old = cache.getIfPresent(key); cache.put(key, value); return old; }
private <K, V> V loadValue(Cache<K, V> cache, K key, Supplier<V> valueSupplier) { if (replay) { return Optional.ofNullable(cache.getIfPresent(key)) .orElseThrow(() -> new PrestoException(NOT_FOUND, "Missing entry found for key: " + key)); } V value = valueSupplier.get(); cache.put(key, value); return value; }
@Override public Set<RemoteRouter> lookupAll(String userId) { Set<RemoteRouter> cached = cache.getIfPresent(userId); if (cached != null) return cached; Set<RemoteRouter> remoteRouters = super.lookupAll(userId); if (remoteRouters != null) { cache.put(userId, remoteRouters); } return remoteRouters; }
public static UnionStructObjectInspector getUnionStructObjectInspector( List<StructObjectInspector> structObjectInspectors) { UnionStructObjectInspector result = cachedUnionStructObjectInspector.getIfPresent(structObjectInspectors); if (result == null) { result = new UnionStructObjectInspector(structObjectInspectors); cachedUnionStructObjectInspector.put(structObjectInspectors, result); } return result; }
private SqlConverter getSqlConverter(String sourceDialect, String targetDialect) throws SQLException { String cacheKey = sourceDialect + "_" + targetDialect; SqlConverter sqlConverter = sqlConverterCache.getIfPresent(cacheKey); if (sqlConverter == null) { sqlConverter = createSqlConverter(sourceDialect, targetDialect); sqlConverterCache.put(cacheKey, sqlConverter); } return sqlConverter; }
private static Model getOrLoadModel(Slice slice) { HashCode modelHash = ModelUtils.modelHash(slice); Model model = MODEL_CACHE.getIfPresent(modelHash); if (model == null) { model = ModelUtils.deserialize(slice); MODEL_CACHE.put(modelHash, model); } return model; } }
public ISource getCachedSource(ISourceAware aware) { String key = createSourceCacheKey(aware); ISource source = sourceMap.getIfPresent(key); if (source != null) return source; synchronized (this) { source = sourceMap.getIfPresent(key); if (source != null) return source; source = createSource(aware); sourceMap.put(key, source); return source; } }
protected Set<String> getOrCreateHashList(String cacheKey) { Set<String> result = cache.getIfPresent(cacheKey); if (result==null) { if (cache.size()>=getMaxKeys()) { cache.invalidateAll(); } cache.put(cacheKey, Collections.synchronizedSet(new LinkedHashSet<>())); } return cache.getIfPresent(cacheKey); }
@Override public void record(long key) { Object value = cache.getIfPresent(key); if (value == null) { cache.put(key, key); policyStats.recordMiss(); } else { policyStats.recordHit(); } }
public Map<Integer, SqlNode> getParamNodes() { paramPath = SqlParamsFinder.PATH_CACHE.getIfPresent(this.sourceTmpl); if (paramPath == null) { this.paramPath = new TreeMap<>(); genParamPath(this.sourceTmpl, new ArrayList<Integer>()); SqlParamsFinder.PATH_CACHE.put(this.sourceTmpl, this.paramPath); } Map<Integer, SqlNode> sqlNodes = new HashMap<>(); for (Map.Entry<Integer, List<Integer>> entry : paramPath.entrySet()) { List<Integer> path = entry.getValue(); sqlNodes.put(entry.getKey(), getParamNode(path, sqlCall, 0)); } return sqlNodes; }
public static BooleanExpression parse(String sql) throws MQFilterException { Object result = PARSE_CACHE.getIfPresent(sql); if (result instanceof MQFilterException) { throw (MQFilterException) result; PARSE_CACHE.put(sql, e); return e; } catch (MQFilterException t) { PARSE_CACHE.put(sql, t); throw t; } finally {
@Override public V get(K key, Callable<? extends V> loader) throws ExecutionException { V value = delegate.getIfPresent(key); if (value == null) { try { value = loader.call(); delegate.put(key, value); cache.incrMissCount(); } catch (Exception e) { throw new ExecutionException(e); } } else { cache.incrHitCount(); } cache.incrTotalCount(); return value; }
public void testSizeConstraint() { final Cache<Integer, Integer> cache = CacheBuilder.newBuilder().maximumSize(4).build(); cache.put(1, 10); cache.put(2, 20); cache.put(3, 30); cache.put(4, 40); cache.put(5, 50); assertEquals(null, cache.getIfPresent(10)); // Order required to remove dependence on access order / write order constraint. assertEquals(Integer.valueOf(20), cache.getIfPresent(2)); assertEquals(Integer.valueOf(30), cache.getIfPresent(3)); assertEquals(Integer.valueOf(40), cache.getIfPresent(4)); assertEquals(Integer.valueOf(50), cache.getIfPresent(5)); cache.put(1, 10); assertEquals(Integer.valueOf(10), cache.getIfPresent(1)); assertEquals(Integer.valueOf(30), cache.getIfPresent(3)); assertEquals(Integer.valueOf(40), cache.getIfPresent(4)); assertEquals(Integer.valueOf(50), cache.getIfPresent(5)); assertEquals(null, cache.getIfPresent(2)); }
public synchronized void addSnippet(final StandardSnippet snippet) { if (snippetMap.getIfPresent(snippet.getId()) != null) { throw new IllegalStateException("Snippet with ID " + snippet.getId() + " already exists"); } snippetMap.put(snippet.getId(), snippet); }
ksqs[i] = new KeySliceQuery(key,query); EntryList result = null; if (!isExpired(ksqs[i])) result = cache.getIfPresent(ksqs[i]); else ksqs[i]=null; if (result!=null) results.put(key,result); if (subresult!=null) { results.put(key,subresult); if (ksqs[i]!=null) cache.put(ksqs[i],subresult);
public void onStart(final EVCacheEvent e) { if(!enableThrottleHotKeys.get()) return; final Cache<String, Integer> cache = getCache(e.getAppName()); if(cache == null) return; for(String key : e.getKeys()) { Integer val = cache.getIfPresent(key); if(val == null) { cache.put(key, START_VAL); } else { cache.put(key, Integer.valueOf(val.intValue() + 1)); } } }
Long id; if (types==null) { id = typeNamesBackup.getIfPresent(schemaName); if (id==null) { id = retriever.retrieveSchemaByName(schemaName); if (id!=null) { //only cache if type exists typeNamesBackup.put(schemaName,id);
public void onError(EVCacheEvent e, Throwable t) { if(!enableThrottleHotKeys.get()) return; final String appName = e.getAppName(); final Cache<String, Integer> cache = getCache(appName); if(cache == null) return; for(String key : e.getKeys()) { Integer val = cache.getIfPresent(key); if(val != null) { cache.put(key, Integer.valueOf(val.intValue() - 1)); } } }
public void testExpireAfterAccess() { final Cache<Integer, Integer> cache = CacheBuilder.newBuilder() .expireAfterAccess(1000, TimeUnit.MILLISECONDS) .ticker(fakeTicker) .build(); cache.put(0, 10); cache.put(2, 30); fakeTicker.advance(999, TimeUnit.MILLISECONDS); assertEquals(Integer.valueOf(30), cache.getIfPresent(2)); fakeTicker.advance(1, TimeUnit.MILLISECONDS); assertEquals(Integer.valueOf(30), cache.getIfPresent(2)); fakeTicker.advance(1000, TimeUnit.MILLISECONDS); assertEquals(null, cache.getIfPresent(0)); }
public void onComplete(EVCacheEvent e) { if(!enableThrottleHotKeys.get()) return; final String appName = e.getAppName(); final Cache<String, Integer> cache = getCache(appName); if(cache == null) return; for(String key : e.getKeys()) { Integer val = cache.getIfPresent(key); if(val != null) { cache.put(key, Integer.valueOf(val.intValue() - 1)); } } }