Java Code Examples for com.github.benmanes.caffeine.cache.RemovalCause#EXPIRED

The following examples show how to use com.github.benmanes.caffeine.cache.RemovalCause#EXPIRED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JCacheEvictionListenerTest.java    From caffeine with Apache License 2.0 6 votes vote down vote up
@Test(dataProvider = "notifications")
public void publishIfEvicted(Integer key, Expirable<Integer> value, RemovalCause cause) {
  listener.delete(key, value, cause);

  if (cause.wasEvicted()) {
    if (cause == RemovalCause.EXPIRED) {
      verify(entryListener).onExpired(any());
    } else {
      verify(entryListener).onRemoved(any());
    }
    assertThat(statistics.getCacheEvictions(), is(1L));
  } else {
    verify(entryListener, never()).onRemoved(any());
    assertThat(statistics.getCacheEvictions(), is(0L));
  }
}
 
Example 2
Source File: JCacheEvictionListener.java    From caffeine with Apache License 2.0 5 votes vote down vote up
@Override
public void delete(K key, @Nullable Expirable<V> expirable, RemovalCause cause) {
  if (cause.wasEvicted() && (expirable != null)) {
    V value = expirable.get();
    if (cause == RemovalCause.EXPIRED) {
      dispatcher.publishExpiredQuietly(cache, key, value);
    } else {
      dispatcher.publishRemovedQuietly(cache, key, value);
    }
    statistics.recordEvictions(1L);
  }
}
 
Example 3
Source File: GuavaCacheFromContext.java    From caffeine with Apache License 2.0 5 votes vote down vote up
@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);
}