private String buildConfiguration(Object cache) { final StringBuilder sb = new StringBuilder(); // getCacheConfiguration() et getMaxElementsOnDisk() n'existent pas en ehcache 1.2 final CacheConfiguration config = ((Ehcache) cache).getCacheConfiguration(); sb.append("ehcache [maxElementsInMemory = ").append(config.getMaxElementsInMemory()); final boolean overflowToDisk = config.isOverflowToDisk(); sb.append(", overflowToDisk = ").append(overflowToDisk); if (overflowToDisk) { sb.append(", maxElementsOnDisk = ").append(config.getMaxElementsOnDisk()); } final boolean eternal = config.isEternal(); sb.append(", eternal = ").append(eternal); if (!eternal) { sb.append(", timeToLiveSeconds = ").append(config.getTimeToLiveSeconds()); sb.append(", timeToIdleSeconds = ").append(config.getTimeToIdleSeconds()); sb.append(", memoryStoreEvictionPolicy = ") .append(config.getMemoryStoreEvictionPolicy()); } sb.append(", diskPersistent = ").append(config.isDiskPersistent()); sb.append(']'); return sb.toString(); }
json.put("Memory Store Eviction Policy", config.getMemoryStoreEvictionPolicy().toString()); json.put("Clean or Flush", config.isClearOnFlush()); json.put("Eternal", config.isEternal()); json.put("Time To Idle Seconds", config.getTimeToIdleSeconds()); json.put("time To Live Seconds", config.getTimeToLiveSeconds());
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(); } }
/** * Accessor */ public boolean isEternal() { return cacheConfiguration.isEternal(); }
/** * {@inheritDoc} */ @Override public boolean isEternal() { return cache.getCacheConfiguration().isEternal(); }
/** * Returns a {@link String} representation of {@link Cache}. */ @Override public String toString() { StringBuilder dump = new StringBuilder(); dump.append("[") .append(" name = ").append(configuration.getName()) .append(" status = ").append(cacheStatus.getStatus()) .append(" eternal = ").append(configuration.isEternal()) .append(" overflowToDisk = ").append(configuration.isOverflowToDisk()) .append(" maxEntriesLocalHeap = ").append(configuration.getMaxEntriesLocalHeap()) .append(" maxEntriesLocalDisk = ").append(configuration.getMaxEntriesLocalDisk()) .append(" memoryStoreEvictionPolicy = ").append(configuration.getMemoryStoreEvictionPolicy()) .append(" timeToLiveSeconds = ").append(configuration.getTimeToLiveSeconds()) .append(" timeToIdleSeconds = ").append(configuration.getTimeToIdleSeconds()) .append(" persistence = ").append(configuration.getPersistenceConfiguration() == null ? "none" : configuration.getPersistenceConfiguration().getStrategy()) .append(" diskExpiryThreadIntervalSeconds = ").append(configuration.getDiskExpiryThreadIntervalSeconds()) .append(registeredEventListeners) .append(" maxBytesLocalHeap = ").append(configuration.getMaxBytesLocalHeap()) .append(" overflowToOffHeap = ").append(configuration.isOverflowToOffHeap()) .append(" maxBytesLocalOffHeap = ").append(configuration.getMaxBytesLocalOffHeap()) .append(" maxBytesLocalDisk = ").append(configuration.getMaxBytesLocalDisk()) .append(" pinned = ") .append(configuration.getPinningConfiguration() != null ? configuration.getPinningConfiguration().getStore().name() : "false") .append(" ]"); return dump.toString(); }
assertEquals("undefinedCache", cache.getName()); assertTrue("default maxElements is correct", config.getMaxEntriesLocalHeap() == 10000); assertFalse("default eternal is correct", config.isEternal()); assertTrue("default timeToLive is correct", config.getTimeToLiveSeconds() == 120); assertTrue("default timeToIdle is correct", config.getTimeToIdleSeconds() == 120);
private void applyDefaultsToElementWithoutLifespanSet(Element element) { if (!element.isLifespanSet()) { element.setLifespanDefaults(TimeUtil.convertTimeToInt(configuration.getTimeToIdleSeconds()), TimeUtil.convertTimeToInt(configuration.getTimeToLiveSeconds()), configuration.isEternal()); } }
/** * An element is expired if the expiration time as given by {@link #getExpirationTime()} is in the past. * <p> * This method in addition propogates the default TTI/TTL values of the supplied cache into this element. * * @param config config to take default parameters from * @return true if the Element is expired, otherwise false. If no lifespan has been set for the Element it is * considered not able to expire. * @see #getExpirationTime() */ public boolean isExpired(CacheConfiguration config) { if (cacheDefaultLifespan) { if (config.isEternal()) { timeToIdle = 0; timeToLive = 0; } else { timeToIdle = TimeUtil.convertTimeToInt(config.getTimeToIdleSeconds()); timeToLive = TimeUtil.convertTimeToInt(config.getTimeToLiveSeconds()); } } return isExpired(); }
/** * Accessor */ public boolean isEternal() { return cacheConfiguration.isEternal(); }
@Override public Object getConfigValue(Ehcache cache) { return cache.getCacheConfiguration().isEternal(); } },
/** * {@inheritDoc} */ @Override public boolean isEternal() { return cache.getCacheConfiguration().isEternal(); }
/** * {@inheritDoc} */ @Override public boolean isEternal() { return cache.getCacheConfiguration().isEternal(); }
@Override public boolean isEternal() { return cache.getCacheConfiguration().isEternal(); }
/** * {@inheritDoc} */ public boolean isEternal() { return cache.getCacheConfiguration().isEternal(); }
@Override public Properties getAll() { CacheConfiguration cc = cache.getCacheConfiguration(); Properties p = new Properties(); p.put("maxEntries", cc.getMaxEntriesLocalHeap()); p.put("timeToLiveSeconds", cc.getTimeToLiveSeconds()); p.put("timeToIdleSeconds", cc.getTimeToIdleSeconds()); p.put("eternal", cc.isEternal()); p.put("statisticsEnabled", cache.isStatisticsEnabled()); return p; } };
element.addAttribute(new SimpleNodeAttribute("eternal", cacheConfiguration.isEternal()).optional(true).defaultValue( CacheConfiguration.DEFAULT_ETERNAL_VALUE)); if (!(cacheConfiguration.getMaxBytesLocalHeap() > 0 || configuration.getMaxBytesLocalHeap() > 0)) {
private void applyDefaultsToElementWithoutLifespanSet(Element element) { if (!element.isLifespanSet()) { element.setLifespanDefaults(TimeUtil.convertTimeToInt(configuration.getTimeToIdleSeconds()), TimeUtil.convertTimeToInt(configuration.getTimeToLiveSeconds()), configuration.isEternal()); } }
private void applyDefaultsToElementWithoutLifespanSet(Element element) { if (!element.isLifespanSet()) { element.setLifespanDefaults(TimeUtil.convertTimeToInt(configuration.getTimeToIdleSeconds()), TimeUtil.convertTimeToInt(configuration.getTimeToLiveSeconds()), configuration.isEternal()); } }
private void applyDefaultsToElementWithoutLifespanSet(Element element) { if (!element.isLifespanSet()) { element.setLifespanDefaults(TimeUtil.convertTimeToInt(configuration.getTimeToIdleSeconds()), TimeUtil.convertTimeToInt(configuration.getTimeToLiveSeconds()), configuration.isEternal()); } }