public Map<String, Object> getCacheConfigurationInformationAsJson(Cache cache) { CacheConfiguration config = cache.getCacheConfiguration(); LinkedHashMap<String, Object> json = new LinkedHashMap<>();
public void testCacheManagerFromConfigFile() { EhCacheManagerFactoryBean cacheManagerFb = new EhCacheManagerFactoryBean(); cacheManagerFb.setConfigLocation(new ClassPathResource("testEhcache.xml", getClass())); cacheManagerFb.setCacheManagerName("myCacheManager"); cacheManagerFb.afterPropertiesSet(); try { CacheManager cm = cacheManagerFb.getObject(); assertTrue("Correct number of caches loaded", cm.getCacheNames().length == 1); Cache myCache1 = cm.getCache("myCache1"); assertFalse("myCache1 is not eternal", myCache1.getCacheConfiguration().isEternal()); assertTrue("myCache1.maxElements == 300", myCache1.getCacheConfiguration().getMaxEntriesLocalHeap() == 300); } finally { cacheManagerFb.destroy(); } }
/** * {@inheritDoc} */ public int getRegionCacheTargetMaxTotalCount(String region) { Cache cache = cacheManager.getCache(region); if (cache != null) { return cache.getCacheConfiguration().getMaxElementsOnDisk(); } else { return -1; } }
/** * {@inheritDoc} */ public boolean isTerracottaHibernateCache(String region) { Cache cache = cacheManager.getCache(region); if (cache != null) { return cache.getCacheConfiguration().isTerracottaClustered(); } else { return false; } }
/** * {@inheritDoc} */ public int getRegionCacheMaxTTLSeconds(String region) { Cache cache = cacheManager.getCache(region); if (cache != null) { return (int) cache.getCacheConfiguration().getTimeToLiveSeconds(); } else { return -1; } }
/** * {@inheritDoc} */ public int getRegionCacheMaxTTISeconds(String region) { Cache cache = cacheManager.getCache(region); if (cache != null) { return (int) cache.getCacheConfiguration().getTimeToIdleSeconds(); } else { return -1; } }
/** * {@inheritDoc} */ public int getRegionCacheTargetMaxInMemoryCount(String region) { Cache cache = cacheManager.getCache(region); if (cache != null) { return cache.getCacheConfiguration().getMaxElementsInMemory(); } else { return -1; } }
/** * {@inheritDoc} */ public boolean isRegionCacheLoggingEnabled(String region) { Cache cache = this.cacheManager.getCache(region); if (cache != null) { return cache.getCacheConfiguration().getLogging(); } else { return false; } }
/** * {@inheritDoc} */ public Results executeQuery(StoreQuery query) { if (searchManager == null) { throw new UnsupportedOperationException("Query execution not supported by this store type: " + getClass().getName()); } DynamicAttributesExtractor dynExtractor = query.getCache().getCacheConfiguration().getDynamicExtractor(); return searchManager.executeQuery(query, attributeExtractors, dynExtractor); }
Class<? extends Ehcache> objectType2 = cacheFb.getObjectType(); assertSame(objectType, objectType2); CacheConfiguration config = cache.getCacheConfiguration(); assertEquals("myCache1", cache.getName()); if (useCacheManagerFb){ cacheFb.afterPropertiesSet(); cache = (Cache) cacheFb.getObject(); config = cache.getCacheConfiguration(); assertEquals("undefinedCache", cache.getName()); assertTrue("default maxElements is correct", config.getMaxEntriesLocalHeap() == 10000); cacheFb.afterPropertiesSet(); cache = (Cache) cacheFb.getObject(); config = cache.getCacheConfiguration();
/** * {@inheritDoc} */ public boolean isRegionCacheOrphanEvictionEnabled(String region) { Cache cache = this.cacheManager.getCache(region); if (cache != null && cache.isTerracottaClustered()) { return cache.getCacheConfiguration().getTerracottaConfiguration().getOrphanEviction(); } else { return false; } }
/** * {@inheritDoc} */ public void setRegionCacheLoggingEnabled(String region, boolean loggingEnabled) { Cache cache = this.cacheManager.getCache(region); if (cache != null) { cache.getCacheConfiguration().setLogging(loggingEnabled); sendNotification(CACHE_REGION_CHANGED, getRegionCacheAttributes(region), region); } }
/** * {@inheritDoc} */ public void setRegionCacheMaxTTISeconds(String region, int maxTTISeconds) { Cache cache = this.cacheManager.getCache(region); if (cache != null) { cache.getCacheConfiguration().setTimeToIdleSeconds(maxTTISeconds); sendNotification(CACHE_REGION_CHANGED, getRegionCacheAttributes(region), region); } }
/** * {@inheritDoc} */ public void setRegionCacheTargetMaxInMemoryCount(String region, int targetMaxInMemoryCount) { Cache cache = this.cacheManager.getCache(region); if (cache != null) { cache.getCacheConfiguration().setMaxElementsInMemory(targetMaxInMemoryCount); sendNotification(CACHE_REGION_CHANGED, getRegionCacheAttributes(region), region); } }
/** * {@inheritDoc} */ public void setRegionCacheTargetMaxTotalCount(String region, int targetMaxTotalCount) { Cache cache = this.cacheManager.getCache(region); if (cache != null) { cache.getCacheConfiguration().setMaxElementsOnDisk(targetMaxTotalCount); sendNotification(CACHE_REGION_CHANGED, getRegionCacheAttributes(region), region); } }
/** * {@inheritDoc} */ public int getRegionCacheOrphanEvictionPeriod(String region) { Cache cache = this.cacheManager.getCache(region); if (cache != null && cache.isTerracottaClustered()) { return cache.getCacheConfiguration().getTerracottaConfiguration().getOrphanEvictionPeriod(); } else { return -1; } }
/** * {@inheritDoc} */ public void setRegionCacheMaxTTLSeconds(String region, int maxTTLSeconds) { Cache cache = this.cacheManager.getCache(region); if (cache != null) { cache.getCacheConfiguration().setTimeToLiveSeconds(maxTTLSeconds); sendNotification(CACHE_REGION_CHANGED, getRegionCacheAttributes(region), region); } }
private void logOnRemoveAllIfPinnedCache() { PinningConfiguration pinningConfiguration = getCacheConfiguration().getPinningConfiguration(); if (pinningConfiguration != null && PinningConfiguration.Store.INCACHE.equals(pinningConfiguration.getStore())) { LOG.warn("Data availability impacted:\n" + "****************************************************************************************\n" + "************************** removeAll called on a pinned cache **************************\n" + "****************************************************************************************"); } }
private static void validateOverAllocation(RuntimeCfg config, Long newValue) { ArrayList<ConfigError> errors = new ArrayList<ConfigError>(); for (Cache cache : getAllActiveCaches(config.cacheManager)) { CacheConfiguration cacheConfiguration = cache.getCacheConfiguration(); errors.addAll(cacheConfiguration.validateCachePools(config.getConfiguration())); errors.addAll(cacheConfiguration.verifyPoolAllocationsBeforeAddingTo(config.cacheManager, newValue, config.getConfiguration().getMaxBytesLocalOffHeap(), config.getConfiguration().getMaxBytesLocalDisk(), null)); } if (!errors.isEmpty()) { throw new InvalidConfigurationException("Can't reduce CacheManager byte tuning by so much", errors); } }
/** * {@inheritDoc} */ public void init(Cache cache) throws CacheException { CacheWriter cacheWriter = cache.getRegisteredCacheWriter(); if (null == cacheWriter) { throw new CacheException("No cache writer was registered for cache " + cache.getName()); } if (cache.getCacheConfiguration().getCacheWriterConfiguration().getWriteCoalescing()) { writeBehind.setOperationsFilter(new CoalesceKeysFilter()); } writeBehind.start(cacheWriter); }