Java Code Examples for com.github.benmanes.caffeine.cache.RemovalCause#wasEvicted()

The following examples show how to use com.github.benmanes.caffeine.cache.RemovalCause#wasEvicted() . 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: BlockCache.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private void releaseLocation(BlockCacheKey blockCacheKey, BlockCacheLocation location, RemovalCause removalCause) {
  if (location == null) {
    return;
  }
  int bankId = location.getBankId();
  int block = location.getBlock();

  // mark the block removed before we release the lock to allow it to be reused
  location.setRemoved(true);

  locks[bankId].clear(block);
  lockCounters[bankId].decrementAndGet();
  for (OnRelease onRelease : onReleases) {
    onRelease.release(blockCacheKey);
  }
  if (removalCause.wasEvicted()) {
    metrics.blockCacheEviction.incrementAndGet();
  }
  metrics.blockCacheSize.decrementAndGet();
}
 
Example 2
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 3
Source File: TinyLfuBlockCache.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public void onRemoval(BlockCacheKey key, Cacheable value, RemovalCause cause) {
  if (!cause.wasEvicted()) {
    // An explicit eviction (invalidation) is not added to the victim cache as the data may
    // no longer be valid for subsequent queries.
    return;
  }

  recordEviction();

  if (victimCache == null) {
    return;
  } else if (victimCache instanceof BucketCache) {
    BucketCache victimBucketCache = (BucketCache) victimCache;
    victimBucketCache.cacheBlockWithWait(key, value, /* inMemory */ true, /* wait */ true);
  } else {
    victimCache.cacheBlock(key, value);
  }
}
 
Example 4
Source File: DefaultMessageDistributor.java    From metron with Apache License 2.0 5 votes vote down vote up
@Override
public void delete(@Nonnull Integer key, @Nullable ProfileBuilder value, @Nonnull RemovalCause cause) {
  if(cause.wasEvicted()) {
    // add the profile to the expired cache
    expiredCache.put(key, value);
    LOG.debug("Profile expired from active cache due to inactivity; profile={}, entity={}, cause={}",
            value.getDefinition().getProfile(), value.getEntity(), cause);

  } else {
    LOG.error("Profile removed from cache unexpectedly. File a bug report; profile={}, entity={}, cause={}",
            value.getDefinition().getProfile(), value.getEntity(), cause);
  }
}
 
Example 5
Source File: DefaultMessageDistributor.java    From metron with Apache License 2.0 5 votes vote down vote up
@Override
public void delete(@Nonnull Integer key, @Nullable ProfileBuilder value, @Nonnull RemovalCause cause) {
  if(cause.wasEvicted()) {
    // the expired profile was NOT flushed in time
    LOG.warn("Expired profile NOT flushed before removal, some state lost; profile={}, entity={}, cause={}",
            value.getDefinition().getProfile(), value.getEntity(), cause);

  } else {
    // the expired profile was flushed successfully
    LOG.debug("Expired profile successfully flushed; profile={}, entity={}, cause={}",
            value.getDefinition().getProfile(), value.getEntity(), cause);
  }
}
 
Example 6
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);
  }
}