public void addCache(String key) { cache.put(key, key); }
public void addCache(String key) { cache.put(key, key); }
void registerAttemptDirs(AttemptPathIdentifier identifier, AttemptPathInfo pathInfo) { LOG.debug("Registering " + identifier + " via watcher"); pathCache.put(identifier, pathInfo); }
public void put(String key, T value) { if (cache == null) return; cache.put(key, value); if (log.isDebugEnabled()) log.debug("PUT : appName : " + appName + "; Key : " + key + "; val : " + value); }
private void loadPrimitiveType(String type) { loadedClasses.put(type, new PrimitiveProto(this, type)); }
public SnapshotTable getSnapshotTable(String resourcePath) throws IOException { try { SnapshotTable r = snapshotCache.get(resourcePath); if (r == null) { r = load(resourcePath, true); snapshotCache.put(resourcePath, r); } return r; } catch (ExecutionException e) { throw new RuntimeException(e.getCause()); } }
public NetworkLocation get(HostAddress host) { NetworkLocation location = cache.getIfPresent(host); if ((location == null) && (negativeCache.getIfPresent(host) == null)) { // Store a value in the cache, so that refresh() is done asynchronously cache.put(host, ROOT_LOCATION); cache.refresh(host); } // Return the root location for anything we couldn't locate return location == null ? ROOT_LOCATION : location; }
/** * cache hmilyTransaction. * * @param hmilyTransaction {@linkplain HmilyTransaction} */ public void cacheHmilyTransaction(final HmilyTransaction hmilyTransaction) { LOADING_CACHE.put(hmilyTransaction.getTransId(), hmilyTransaction); }
@Override public CompletableFuture<Versioned<V>> getOrDefault(K key, V defaultValue) { return cache.getUnchecked(key).thenCompose(r -> { if (r == null) { CompletableFuture<Versioned<V>> versioned = backingMap.getOrDefault(key, defaultValue); cache.put(key, versioned); return versioned; } else { return CompletableFuture.completedFuture(r); } }).whenComplete((r, e) -> { if (e != null) { cache.invalidate(key); } }); }
/** * Sets the status of the ASG. * * @param asgName The name of the ASG * @param enabled true to enable, false to disable */ public void setStatus(String asgName, boolean enabled) { String asgAccountId = getASGAccount(asgName); asgCache.put(new CacheKey(asgAccountId, asgName), enabled); }
public void set(ControlPanelTypes type, boolean newValue) throws Exception { cache.put(type, newValue); preferences.putBoolean(makeKey(type), newValue); preferences.flush(); }
private DictionaryInfo saveNewDict(DictionaryInfo newDictInfo) throws IOException { save(newDictInfo); dictCache.put(newDictInfo.getResourcePath(), newDictInfo); return newDictInfo; }
public SnapshotTable trySaveNewSnapshot(SnapshotTable snapshotTable) throws IOException { String dupTable = checkDupByContent(snapshotTable); if (dupTable != null) { logger.info("Identical snapshot content " + snapshotTable + ", reuse existing snapshot at " + dupTable); return getSnapshotTable(dupTable); } save(snapshotTable); snapshotCache.put(snapshotTable.getResourcePath(), snapshotTable); return snapshotTable; }
public CachingAsyncLeaderElector(AsyncLeaderElector<T> delegateLeaderElector, CacheConfig cacheConfig) { super(delegateLeaderElector); cache = CacheBuilder.newBuilder() .maximumSize(cacheConfig.getSize()) .build(CacheLoader.from(super::getLeadership)); cacheUpdater = event -> { Leadership<T> leadership = event.newLeadership(); cache.put(event.topic(), CompletableFuture.completedFuture(leadership)); }; statusListener = status -> { if (status == PrimitiveState.SUSPENDED || status == PrimitiveState.CLOSED) { cache.invalidateAll(); } }; addListener(cacheUpdater); addStateChangeListener(statusListener); }
public void testLoadingCache() throws ExecutionException { CacheLoader<Integer, Integer> loader = new CacheLoader<Integer, Integer>() { int i = 0; @Override public Integer load(Integer key) throws Exception { return i++; } }; LoadingCache<Integer, Integer> cache = CacheBuilder.newBuilder().build(loader); cache.put(10, 20); Map<Integer, Integer> map = cache.getAll(ImmutableList.of(10, 20, 30, 54, 443, 1)); assertEquals(Integer.valueOf(20), map.get(10)); assertEquals(Integer.valueOf(0), map.get(20)); assertEquals(Integer.valueOf(1), map.get(30)); assertEquals(Integer.valueOf(2), map.get(54)); assertEquals(Integer.valueOf(3), map.get(443)); assertEquals(Integer.valueOf(4), map.get(1)); assertEquals(Integer.valueOf(5), cache.get(6)); assertEquals(Integer.valueOf(6), cache.apply(7)); }
@Subscribe public void onPostItemComposition(PostItemComposition event) { itemCompositions.put(event.getItemComposition().getId(), event.getItemComposition()); }
public void testReload_interrupted() { try { LoadingCache<Integer, Integer> cache = CaffeinatedGuava.build( Caffeine.newBuilder().executor(MoreExecutors.directExecutor()), new CacheLoader<Integer, Integer>() { @Override public Integer load(Integer key) throws Exception { throw new InterruptedException(); } }); cache.put(1, 1); cache.refresh(1); } catch (CacheLoaderException e) { assertTrue(Thread.currentThread().isInterrupted()); } }
public void testReload_throwable() { try { LoadingCache<Integer, Integer> cache = CaffeinatedGuava.build( Caffeine.newBuilder().executor(MoreExecutors.directExecutor()), new CacheLoader<Integer, Integer>() { @Override public Integer load(Integer key) throws Exception { throw new Exception(); } }); cache.put(1, 1); cache.refresh(1); } catch (CacheLoaderException e) { assertTrue(Thread.currentThread().isInterrupted()); } }
@SuppressWarnings("deprecation") public void testLoadingCache() throws ExecutionException { CacheLoader<Integer, Integer> loader = new CacheLoader<Integer, Integer>() { int i = 0; @Override public Integer load(Integer key) throws Exception { return i++; } }; LoadingCache<Integer, Integer> cache = CaffeinatedGuava.build(Caffeine.newBuilder(), loader); cache.put(10, 20); ImmutableSet<Integer> keys = ImmutableSet.of(10, 20, 30, 54, 443, 1); Map<Integer, Integer> map = cache.getAll(keys); // Original test depended on order, but that was only expected for the emulated implementation assertEquals(keys, map.keySet()); assertEquals(ImmutableSet.of(0, 1, 2, 3, 4, 20), ImmutableSet.copyOf(map.values())); assertEquals(Integer.valueOf(5), cache.get(6)); assertEquals(Integer.valueOf(6), cache.apply(7)); }
public SnapshotTable rebuildSnapshot(IReadableTable table, TableDesc tableDesc, String overwriteUUID) throws IOException { SnapshotTable snapshot = new SnapshotTable(table, tableDesc.getIdentity()); snapshot.setUuid(overwriteUUID); snapshot.takeSnapshot(table, tableDesc); SnapshotTable existing = getSnapshotTable(snapshot.getResourcePath()); snapshot.setLastModified(existing.getLastModified()); save(snapshot); snapshotCache.put(snapshot.getResourcePath(), snapshot); return snapshot; }