List of usage examples for com.google.common.cache RemovalCause EXPLICIT
RemovalCause EXPLICIT
To view the source code for com.google.common.cache RemovalCause EXPLICIT.
Click Source Link
From source file:org.janusgraph.graphdb.transaction.vertexcache.GuavaVertexCache.java
public GuavaVertexCache(final long maxCacheSize, final int concurrencyLevel, final int initialDirtySize) { volatileVertices = new NonBlockingHashMapLong<InternalVertex>(initialDirtySize); log.debug("Created dirty vertex map with initial size {}", initialDirtySize); cache = CacheBuilder.newBuilder().maximumSize(maxCacheSize).concurrencyLevel(concurrencyLevel) .removalListener(new RemovalListener<Long, InternalVertex>() { @Override/*from w w w. jav a 2 s. c o m*/ public void onRemoval(RemovalNotification<Long, InternalVertex> notification) { if (notification.getCause() == RemovalCause.EXPLICIT) { //Due to invalidation at the end assert volatileVertices.isEmpty(); return; } //Should only get evicted based on size constraint or replaced through add assert (notification.getCause() == RemovalCause.SIZE || notification.getCause() == RemovalCause.REPLACED) : "Cause: " + notification.getCause(); InternalVertex v = notification.getValue(); if (v.isModified()) { volatileVertices.putIfAbsent(notification.getKey(), v); } } }).build(); log.debug("Created vertex cache with max size {}", maxCacheSize); }
From source file:org.apache.beam.runners.dataflow.worker.ReaderCache.java
/** Cache reader for {@code cacheDuration}. */ ReaderCache(Duration cacheDuration) { this.cache = CacheBuilder.newBuilder().expireAfterWrite(cacheDuration.getMillis(), TimeUnit.MILLISECONDS) .removalListener((RemovalNotification<KV<String, ByteString>, CacheEntry> notification) -> { if (notification.getCause() != RemovalCause.EXPLICIT) { LOG.info("Closing idle reader for {}", keyToString(notification.getKey())); closeReader(notification.getKey(), notification.getValue()); }/* w w w .ja v a 2 s . c om*/ }).build(); }
From source file:org.apache.beam.runners.dataflow.worker.WindmillStateCache.java
public WindmillStateCache() { final Weigher<Weighted, Weighted> weigher = Weighers.weightedKeysAndValues(); stateCache = CacheBuilder.newBuilder().maximumWeight(100000000 /* 100 MB */).recordStats().weigher(weigher) .removalListener(removal -> { if (removal.getCause() != RemovalCause.REPLACED) { synchronized (this) { StateId id = (StateId) removal.getKey(); if (removal.getCause() != RemovalCause.EXPLICIT) { // When we invalidate a key explicitly, we'll also update the keyIndex, so // no need to do it here. keyIndex.remove(id.getComputationKey(), id); }/*from w w w . j av a 2s. c o m*/ displayedWeight -= weigher.weigh(id, removal.getValue()); } } }).build(); }
From source file:desmedt.frederik.cachebenchmarking.cache.CacheLIRS.java
private void setSegment(int index, Segment<K, V> s) { Segment<K, V> old = segments[index]; segments[index] = s;/*from w w w .ja v a2 s . co m*/ if (evicted != null && old != null && old != s) { old.evictedAll(RemovalCause.EXPLICIT); } }
From source file:desmedt.frederik.cachebenchmarking.cache.CacheLIRS.java
/** * Remove an entry. Both resident and non-resident entries can be * removed./*from w ww . j a v a 2s . c o m*/ * * @param key the key (may not be null) */ @Override public void invalidate(Object key) { int hash = getHash(key); getSegment(hash).invalidate(key, hash, RemovalCause.EXPLICIT); }
From source file:desmedt.frederik.cachebenchmarking.cache.CacheLIRS.java
void clear() { for (Segment<K, V> s : segments) { synchronized (s) { if (evicted != null) { s.evictedAll(RemovalCause.EXPLICIT); }/* w w w .ja v a 2 s . com*/ s.clear(); } } }