List of usage examples for com.google.common.cache RemovalCause SIZE
RemovalCause SIZE
To view the source code for com.google.common.cache RemovalCause SIZE.
Click Source Link
From source file:org.gradle.cache.internal.LoggingEvictionListener.java
@Override public void onRemoval(RemovalNotification<Object, Object> notification) { if (notification.getCause() == RemovalCause.SIZE) { if (evictionCounter % logInterval == 0) { logger.info("Cache entries evicted. In-memory cache of {}: Size{{}} MaxSize{{}}, {} {}", cacheId, cache.size(), maxSize, cache.stats(), EVICTION_MITIGATION_MESSAGE); }/* ww w .j a v a 2 s. c o m*/ evictionCounter++; } }
From source file:org.gradle.api.internal.changedetection.state.LoggingEvictionListener.java
@Override public void onRemoval(RemovalNotification<Object, Object> notification) { if (notification.getCause() == RemovalCause.SIZE) { if (evictionCounter % logInterval == 0) { logger.log(LogLevel.INFO,/*from w w w . j av a2s. c om*/ "Cache entries evicted. In-memory cache of {}: Size{{}} MaxSize{{}}, {} {}", cacheId, cache.size(), maxSize, cache.stats(), EVICTION_MITIGATION_MESSAGE); } evictionCounter++; } }
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 ww w. j av 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.auraframework.impl.cache.CacheEvictionListenerImpl.java
/** * Broken into a separate routine because RemovalNotification is a final class with no constructor. */// w w w. ja v a 2 s .c o m @Override public void onRemoval(RemovalNotification<K, T> notification) { onRemoval(notification.getCause() == RemovalCause.SIZE); }
From source file:com.qubole.rubix.bookkeeper.BookKeeper.java
private static synchronized void initializeCache(final Configuration conf) { long avail = 0; for (int d = 0; d < CacheConfig.numDisks(conf); d++) { avail += new File(CacheConfig.getDirPath(conf, d)).getUsableSpace(); }/*from w w w. jav a 2 s. com*/ avail = avail / 1024 / 1024; final long total = avail; log.info("total free space " + avail + "MB"); fileMetadataCache = CacheBuilder.newBuilder().weigher(new Weigher<String, FileMetadata>() { @Override public int weigh(String key, FileMetadata md) { // weights are in MB to avoid overflowing due to large files // This is not accurate, we are placing weight as whole filesize // Rather it should be dynamic and should be equal to size of file data cached // But guava needs weight fixed at init // TODO: find a way to set weight accurately and get away from current workaround int weight = (int) (md.getOccupiedSize() / 1024 / 1024); log.info("weighing key " + key + " as " + weight); return weight; } }).maximumWeight((long) (avail * 1.0 * CacheConfig.getCacheDataFullnessPercentage(conf) / 100.0)) .expireAfterWrite(CacheConfig.getCacheDataExpirationAfterWrite(conf), TimeUnit.SECONDS) .removalListener(new RemovalListener<String, FileMetadata>() { public void onRemoval(RemovalNotification<String, FileMetadata> notification) { try { FileMetadata md = notification.getValue(); if (notification.getCause() == RemovalCause.EXPIRED) { // This is to workaround the static weighing of Guava Cache, logic goes like this: // We evict aggressively but do not delete backing data unless running out of space // On next get() on cache, fileMetadata.getOccupiedSize will return size occupied on disk md.close(); log.info("Evicting " + md.getRemotePath().toString() + " due to " + notification.getCause()); return; } if (notification.getCause() == RemovalCause.SIZE) { // Here also we wont delete unless very close to disk full long free = 0; for (int d = 0; d < CacheConfig.numDisks(conf); d++) { free += new File(CacheConfig.getDirPath(conf, d)).getUsableSpace(); } if (free > total * 1.0 * (100.0 - CacheConfig.getCacheDataFullnessPercentage(conf) / 100)) { // still havent utilized the allowed space so do not delete the backing file md.close(); log.warn("Evicting " + md.getRemotePath().toString() + " due to " + notification.getCause()); return; } } //if file has been modified in cloud, its entry will be deleted due to "EXPLICIT" log.warn("deleting entry for" + md.getRemotePath().toString() + " due to " + notification.getCause()); md.closeAndCleanup(); } catch (IOException e) { throw Throwables.propagate(e); } } }).build(); }
From source file:it.geosolutions.concurrent.ConcurrentTileCacheMultiMap.java
/** * Creation of a listener to use for handling the removed tiles * /* w w w .j av a 2s. c om*/ * @param diagnostic * @return */ private RemovalListener<Object, CachedTileImpl> createListener(final boolean diagnostic) { return new RemovalListener<Object, CachedTileImpl>() { public void onRemoval(RemovalNotification<Object, CachedTileImpl> n) { // if a tile is manually removed, the diagnosticEnabled already consider // it in // the remove() method if (diagnostic) { synchronized (cacheObject) { CachedTileImpl cti = n.getValue(); // Update of the tile action if (n.wasEvicted()) { cti.setAction(Actions.REMOVAL_FROM_EVICTION); } else { cti.setAction(Actions.MANUAL_REMOVAL); } // Update Cache Memory Size currentCacheCapacity.addAndGet(-cti.getTileSize()); // Removal from the multimap removeTileFromMultiMap(cti); setChanged(); notifyObservers(cti); } } else { CachedTileImpl cti = n.getValue(); if (n.getCause() == RemovalCause.SIZE) { // Logging if the tile is removed because the size is exceeded if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Removing from MultiMap for size"); } } removeTileFromMultiMap(cti); } } }; }
From source file:org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.java
private Cache<MavenProjectFacade, MavenProject> createProjectCache() { final RemovalListener<MavenProjectFacade, MavenProject> removalListener = new RemovalListener<MavenProjectFacade, MavenProject>() { public void onRemoval(RemovalNotification<MavenProjectFacade, MavenProject> notification) { if (notification.getCause() == RemovalCause.SIZE || notification.getCause() == RemovalCause.REPLACED) { // there is currently no good way to determine if MavenProject instance is still being used or not // for now assume that cache entries removed from project cache can only be referenced by context map final MavenProjectFacade facade = notification.getKey(); final MavenProject mavenProject = notification.getValue(); final Map<MavenProjectFacade, MavenProject> contextProjects = getContextProjects(); if (contextProjects != null && !contextProjects.containsKey(facade)) { flushMavenCaches(facade.getPomFile(), facade.getArtifactKey(), mavenProject, false); }/* w ww .j a v a 2s .c om*/ } } }; return CacheBuilder.newBuilder().maximumSize(5).removalListener(removalListener).build(); }