@Override 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); } } })
@Override public void onRemoval(RemovalNotification<State, Set<KeyAndSource>> notification) { Preconditions.checkState(RemovalCause.COLLECTED.equals(notification.getCause())); cleanUpForCollectedState(notification.getValue()); } })
@Override public void onRemoval(RemovalNotification<Integer, Integer> notification) { switch (notification.getCause()) { case EXPIRED: stats[0]++; break; case EXPLICIT: stats[1]++; break; case REPLACED: stats[2]++; break; case SIZE: stats[3]++; break; default: throw new IllegalStateException("No collected exceptions in GWT CacheBuilder."); } } };
@Override public void onRemoval(RemovalNotification<String, User> notification) { log.debug("Clear user cache for {} due to {}", notification.getKey(), notification.getCause()); } }).build();
@Override public void onRemoval(RemovalNotification<String, Authentication> notification) { KylinAuthenticationProvider.logger.debug("User cache {} is removed due to {}", notification.getKey(), notification.getCause()); } }).build();
@Override public void onRemoval(RemovalNotification<String, User> notification) { log.debug("Clear user cache for {} due to {}", notification.getKey(), notification.getCause()); } }).build();
@Override public void onRemoval(RemovalNotification<StandardTransactionId, TxEntry> notification) { RemovalCause cause = notification.getCause(); Preconditions.checkArgument(cause == RemovalCause.EXPIRED, "Unexpected removal cause [%s] for transaction [%s]", cause, notification.getKey()); TxEntry entry = notification.getValue(); if (entry.status == LogTxStatus.SECONDARY_FAILURE || entry.status == LogTxStatus.PRIMARY_SUCCESS) { failureTxCounter.incrementAndGet(); fixSecondaryFailure(notification.getKey(), entry); } else { successTxCounter.incrementAndGet(); } } })
@Override public void onRemoval(RemovalNotification<AuthCredentials, User> notification) { log.debug("Clear user cache for {} due to {}", notification.getKey().getUsername(), notification.getCause()); } }).build();
@Override public void onRemoval(RemovalNotification<Object, Object> notification) { System.out.println(notification.getCause()); } }).build();
@Override public void onRemoval(RemovalNotification<AuthCredentials, User> notification) { log.debug("Clear user cache for {} due to {}", notification.getKey().getUsername(), notification.getCause()); } }).build();
@Inject public NetflowV9CodecAggregator() { // TODO customize this.templateCache = CacheBuilder.newBuilder() .maximumSize(5000) .removalListener(notification -> LOG.debug("Removed {} from template cache for reason {}", notification.getKey(), notification.getCause())) .recordStats() .build(); this.packetCache = CacheBuilder.newBuilder() .expireAfterWrite(1, TimeUnit.MINUTES) .maximumWeight(Size.megabytes(1).toBytes()) .removalListener((RemovalListener<TemplateKey, Queue<PacketBytes>>) notification -> LOG.debug("Removed {} from packet cache for reason {}", notification.getKey(), notification.getCause())) .weigher((key, value) -> value.stream().map(PacketBytes::readableBytes).reduce(0, Integer::sum)) .recordStats() .build(); }
public void testExpiration_invalidateAll() { FakeTicker ticker = new FakeTicker(); QueuingRemovalListener<Integer, Integer> listener = TestingRemovalListeners.queuingRemovalListener(); Cache<Integer, Integer> cache = CacheBuilder.newBuilder() .expireAfterAccess(1, TimeUnit.MINUTES) .removalListener(listener) .ticker(ticker) .build(); cache.put(1, 1); ticker.advance(10, TimeUnit.MINUTES); cache.invalidateAll(); assertThat(listener.poll().getCause()).isEqualTo(RemovalCause.EXPIRED); }
public void testGet() { Object computed = new Object(); LoadingCache<Object, Object> cache = CacheBuilder.newBuilder() .maximumSize(0) .removalListener(listener) .build(constantLoader(computed)); Object key = new Object(); assertSame(computed, cache.getUnchecked(key)); RemovalNotification<Object, Object> notification = listener.remove(); assertSame(key, notification.getKey()); assertSame(computed, notification.getValue()); assertSame(RemovalCause.SIZE, notification.getCause()); assertTrue(listener.isEmpty()); checkEmpty(cache); }
public void testGet_expireAfterAccess() { Object computed = new Object(); LoadingCache<Object, Object> cache = CacheBuilder.newBuilder() .expireAfterAccess(0, SECONDS) .removalListener(listener) .build(constantLoader(computed)); Object key = new Object(); assertSame(computed, cache.getUnchecked(key)); RemovalNotification<Object, Object> notification = listener.remove(); assertSame(key, notification.getKey()); assertSame(computed, notification.getValue()); assertSame(RemovalCause.SIZE, notification.getCause()); assertTrue(listener.isEmpty()); checkEmpty(cache); }
public void testGet_expireAfterWrite() { Object computed = new Object(); LoadingCache<Object, Object> cache = CacheBuilder.newBuilder() .expireAfterWrite(0, SECONDS) .removalListener(listener) .build(constantLoader(computed)); Object key = new Object(); assertSame(computed, cache.getUnchecked(key)); RemovalNotification<Object, Object> notification = listener.remove(); assertSame(key, notification.getKey()); assertSame(computed, notification.getValue()); assertSame(RemovalCause.SIZE, notification.getCause()); assertTrue(listener.isEmpty()); checkEmpty(cache); }
static <K, V> void assertNotified( QueuingRemovalListener<K, V> listener, K key, V value, RemovalCause cause) { RemovalNotification<K, V> notification = listener.remove(); assertSame(key, notification.getKey()); assertSame(value, notification.getValue()); assertSame(cause, notification.getCause()); }
@Override public void onRemoval(RemovalNotification<K, V> notification) { RemovalCause cause = RemovalCause.valueOf(notification.getCause().name()); if (translateZeroExpire && (cause == RemovalCause.SIZE)) { // Guava internally uses sizing logic for null cache case cause = RemovalCause.EXPIRED; } delegate.onRemoval(notification.getKey(), notification.getValue(), cause); } }
public void testGet() { Object computed = new Object(); LoadingCache<Object, Object> cache = CaffeinatedGuava.build(Caffeine.newBuilder() .executor(MoreExecutors.directExecutor()) .maximumSize(0) .removalListener(listener), constantLoader(computed)); Object key = new Object(); assertSame(computed, cache.getUnchecked(key)); RemovalNotification<Object, Object> notification = listener.remove(); assertSame(key, notification.getKey()); assertSame(computed, notification.getValue()); assertSame(RemovalCause.SIZE, notification.getCause()); assertTrue(listener.isEmpty()); checkEmpty(cache); }
public void testGet_expireAfterWrite() { // Guava sends a notification with SIZE as the removal cause by redefining 0 expiration as // a maximum size of zero. This is not done as expiration can be dynamically updated Object computed = new Object(); LoadingCache<Object, Object> cache = CaffeinatedGuava.build(Caffeine.newBuilder() .executor(MoreExecutors.directExecutor()) .expireAfterWrite(0, SECONDS) .removalListener(listener), constantLoader(computed)); Object key = new Object(); assertSame(computed, cache.getUnchecked(key)); RemovalNotification<Object, Object> notification = listener.remove(); assertSame(key, notification.getKey()); assertSame(computed, notification.getValue()); assertSame(RemovalCause.EXPIRED, notification.getCause()); assertTrue(listener.isEmpty()); checkEmpty(cache); }
public void testGet_expireAfterAccess() { // Guava sends a notification with SIZE as the removal cause by redefining 0 expiration as // a maximum size of zero. This is not done as expiration can be dynamically updated Object computed = new Object(); LoadingCache<Object, Object> cache = CaffeinatedGuava.build(Caffeine.newBuilder() .executor(MoreExecutors.directExecutor()) .expireAfterAccess(0, SECONDS) .removalListener(listener), constantLoader(computed)); Object key = new Object(); assertSame(computed, cache.getUnchecked(key)); RemovalNotification<Object, Object> notification = listener.remove(); assertSame(key, notification.getKey()); assertSame(computed, notification.getValue()); assertSame(RemovalCause.EXPIRED, notification.getCause()); assertTrue(listener.isEmpty()); checkEmpty(cache); }