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("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()); if (config.getPersistenceConfiguration() != null) {
/** * Accessor */ public long getTimeToIdleSeconds() { return cacheConfiguration.getTimeToIdleSeconds(); }
/** * {@inheritDoc} */ public int getRegionCacheMaxTTISeconds(String region) { Cache cache = cacheManager.getCache(region); if (cache != null) { return (int) cache.getCacheConfiguration().getTimeToIdleSeconds(); } else { return -1; } }
/** * {@inheritDoc} */ @Override public long getTimeToIdleSeconds() { return cache.getCacheConfiguration().getTimeToIdleSeconds(); }
assertFalse("default eternal is correct", config.isEternal()); assertTrue("default timeToLive is correct", config.getTimeToLiveSeconds() == 120); assertTrue("default timeToIdle is correct", config.getTimeToIdleSeconds() == 120); assertTrue("default diskExpiryThreadIntervalSeconds is correct", config.getDiskExpiryThreadIntervalSeconds() == 120); assertTrue("overridden maxElements is correct", config.getMaxEntriesLocalHeap() == 5); assertTrue("default timeToLive is correct", config.getTimeToLiveSeconds() == 8); assertTrue("default timeToIdle is correct", config.getTimeToIdleSeconds() == 7); assertTrue("overridden diskExpiryThreadIntervalSeconds is correct", config.getDiskExpiryThreadIntervalSeconds() == 10);
/** * 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(); }
@Test public void shouldReturnCacheConfigsFromPropertiesFile(){ List<CacheConfiguration> cacheConfigurations = CachePropertiesUtil.getCacheConfigurations(); assertThat(cacheConfigurations.size(), is(2)); assertThat(cacheConfigurations.get(0).getTimeToIdleSeconds(), is(300L)); } }
/** * Sets whether elements are eternal. If eternal, timeouts are ignored and the element is never expired. False by default. * * @param eternal true for eternal */ public final void setEternal(boolean eternal) { checkDynamicChange(); isEternalValueConflictingWithTTIOrTTL(eternal, getTimeToLiveSeconds(), getTimeToIdleSeconds()); this.eternal = eternal; if (eternal) { setTimeToIdleSeconds(0); setTimeToLiveSeconds(0); } }
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 long getTimeToIdleSeconds() { return cacheConfiguration.getTimeToIdleSeconds(); }
/** * {@inheritDoc} */ public int getRegionCacheMaxTTISeconds(String region) { Cache cache = cacheManager.getCache(region); if (cache != null) { return (int) cache.getCacheConfiguration().getTimeToIdleSeconds(); } else { return -1; } }
/** * {@inheritDoc} */ @Override public long getTimeToIdleSeconds() { return cache.getCacheConfiguration().getTimeToIdleSeconds(); }
@Override @Nonnull public final Long currentExpireAfterAccessMillis() { return MILLISECONDS.convert( delegate.getCacheConfiguration().getTimeToIdleSeconds(), SECONDS); }
@Override public Object getConfigValue(Ehcache cache) { return cache.getCacheConfiguration().getTimeToIdleSeconds(); } },
@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; } };
ToolkitCacheConfigBuilder builder = new ToolkitCacheConfigBuilder(); final TerracottaConfiguration terracottaConfiguration = ehcacheConfig.getTerracottaConfiguration(); builder.maxTTISeconds((int) ehcacheConfig.getTimeToIdleSeconds()); builder.maxTTLSeconds((int) ehcacheConfig.getTimeToLiveSeconds()); builder.localCacheEnabled(terracottaConfiguration.isLocalCacheEnabled());
element.addAttribute(new SimpleNodeAttribute("copyOnRead", cacheConfiguration.isCopyOnRead()).optional(true).defaultValue( CacheConfiguration.DEFAULT_COPY_ON_READ)); element.addAttribute(new SimpleNodeAttribute("timeToIdleSeconds", cacheConfiguration.getTimeToIdleSeconds()).optional(true) .defaultValue(CacheConfiguration.DEFAULT_TTI)); element.addAttribute(new SimpleNodeAttribute("timeToLiveSeconds", cacheConfiguration.getTimeToLiveSeconds()).optional(true)
private void applyDefaultsToElementWithoutLifespanSet(Element element) { if (!element.isLifespanSet()) { element.setLifespanDefaults(TimeUtil.convertTimeToInt(configuration.getTimeToIdleSeconds()), TimeUtil.convertTimeToInt(configuration.getTimeToLiveSeconds()), configuration.isEternal()); } }