private static void verifyCacheHasNoEviction(AdvancedCache<?, ?> cache) { if (cache.getCacheConfiguration().eviction().strategy().isEnabled()) throw new IllegalArgumentException("DistributedSegmentReadLocker is not reliable when using a cache with eviction enabled, disable eviction on this cache instance"); }
@ManagedName("MaxEntries") @ManagedDescription("Maximum number of entries in a cache instance. -1 means no limit.") public int getMaxSize() { return cache.getCacheConfiguration().eviction().maxEntries(); }
@ManagedName("MaxEntries") @ManagedDescription("Maximum number of entries in a cache instance. -1 means no limit.") public int getMaxSize() { return cache.getCacheConfiguration().eviction().maxEntries(); }
public void testSmallCache() { // Check that we have the correctly configured cache assertEquals(smallCache.getCacheConfiguration().eviction().maxEntries(), 10); } }
public void testVeryLargeCache() { assertEquals(largeCache.getCacheConfiguration().eviction().maxEntries(), 1000); }
public void testTinyCache() { // Check that we have the correctly configured cache assertEquals(tinyCache.getCacheConfiguration().eviction().maxEntries(), 1); }
public void testSmallCache() { assertEquals(smallCache.getCacheConfiguration().eviction().maxEntries(), 7); assertEquals(observers.getCacheStartedEventCount(), 1); } }
public void testLargeCache() { assertEquals(largeCache.getCacheConfiguration().eviction().maxEntries(), 100); }
public void testDefaultConfiguration() { assertEquals(cache.getCacheConfiguration().eviction().maxEntries(), 16); assertEquals(cache.getName(), DEFAULT_CACHE_NAME); }
public void testSpecificCacheManager() throws Exception { assertEquals(largeCache.getCacheConfiguration().eviction().maxEntries(), 2000); assertEquals(largeCache.getCacheConfiguration().eviction().strategy(), LIRS); assertEquals(largeCache.getCacheManager().getDefaultCacheConfiguration().eviction().maxEntries(), 4000); assertEquals(largeCache.getCacheManager().getDefaultCacheConfiguration().eviction().strategy(), LIRS); assertEquals(smallCache.getCacheConfiguration().eviction().maxEntries(), 20); assertEquals(smallCache.getCacheConfiguration().eviction().strategy(), LIRS); assertEquals(smallCache.getCacheManager().getDefaultCacheConfiguration().eviction().maxEntries(), 4000); assertEquals(smallCache.getCacheManager().getDefaultCacheConfiguration().eviction().strategy(), LIRS); // asserts that the small and large cache are defined in the same cache manager assertTrue(smallCache.getCacheManager().equals(largeCache.getCacheManager())); assertFalse(smallCache.getCacheManager().equals(cache.getCacheManager())); // check that the default configuration has not been modified assertEquals(cache.getCacheConfiguration().eviction().strategy(), NONE); assertEquals(cache.getCacheConfiguration().eviction().maxEntries(), -1); assertEquals(cache.getCacheManager().getDefaultCacheConfiguration().eviction().strategy(), NONE); } }
public void testQuickCache() { assertEquals(quickCache.getCacheConfiguration().eviction().maxEntries(), 1000); assertEquals(quickCache.getCacheConfiguration().expiration().wakeUpInterval(), 1); } }
/** * Checks if the specified cache is configured in "stateless mode". * * @param cache The cache to check. * * @return {@code true} if the cache is configured in "stateless mode", * else {@code false}. */ public static boolean detectStatelessMode(final Cache cache) { final boolean isLocal = CacheMode.LOCAL.equals(cache.getCacheConfiguration().clustering().cacheMode()); final boolean isSizeOne = 1 == cache.getCacheConfiguration().eviction().size(); if (isLocal && isSizeOne) { return true; } return false; }
@Override public void registerAttributes(ManagementResourceRegistration resourceRegistration) { final OperationStepHandler restartCacheWriteHandler = new RestartServiceWriteAttributeHandler( resource.getPathElement().getKey(), resource.getServiceInstaller(), CacheServiceName.CONFIGURATION, attributes); resourceRegistration.registerReadWriteAttribute(EVICTION_STRATEGY, CacheReadAttributeHandler.INSTANCE, restartCacheWriteHandler); resourceRegistration.registerReadWriteAttribute(TYPE, CacheReadAttributeHandler.INSTANCE, restartCacheWriteHandler); resourceRegistration.registerReadWriteAttribute(SIZE, CacheReadAttributeHandler.INSTANCE, new RuntimeCacheConfigurationWriteAttributeHandler(SIZE, (configuration, newSize) -> configuration.eviction().size(newSize.asLong()))); } }
private static void validateMetadataCache(Cache<?, ?> cache, String indexName) { Configuration configuration = cache.getCacheConfiguration(); if (configuration.eviction().strategy().isEnabled()) { throw log.evictionNotAllowedInMetadataCache(indexName, cache.getName()); } if (configuration.persistence().usingStores() && !configuration.persistence().preload()) { throw log.preloadNeededIfPersistenceIsEnabledForMetadataCache(indexName, cache.getName()); } }