14

If I have the following configuration:

<defaultCache timeToIdleSeconds="120" timeToLiveSeconds="120" /> <cache name="test" timeToLiveSeconds="300" /> 

What will be the value of timeToIdleSeconds for the cache test? Will it be inherited from the default cache, and thus be equal to 120, or will it take the default value as given in the manual, which is 0 (infinity)?

2 Answers 2

15

The timeToIdleSeconds will be default value and not inherit from "defaultCache". The "defaultCache" is a bit misnomer/misleading, in the sense that it does not provide "defaults" for every cache, but its just a way of specifying config for caches that can/are added dynamically - using cacheManager.addCache(String cacheName).

From http://www.ehcache.org/ehcache.xml, documentation for that tag reads

 Default Cache configuration. These settings will be applied to caches created programmatically using CacheManager.add(String cacheName). This element is optional, and using CacheManager.add(String cacheName) when its not present will throw CacheException The defaultCache has an implicit name "default" which is a reserved cache name. 
Sign up to request clarification or add additional context in comments.

2 Comments

I did read that text, but to me it does not seem to be too clear.
FYI, the defaultCache settings are also used when calling CacheManager#addCacheIfAbsent(String cacheName).
0
private Ehcache cloneDefaultCache(final String cacheName) { if (defaultCache == null) { return null; } Ehcache cache; try { cache = (Ehcache) defaultCache.clone(); } catch (CloneNotSupportedException e) { throw new CacheException("Failure cloning default cache. Initial cause was " + e.getMessage(), e); } if (cache != null) { cache.setName(cacheName); } return cache; } 
Method cloneDefaultCache(String) Found usages (2 usages found) Library (2 usages found) Unclassified usage (2 usages found) Maven: net.sf.ehcache:ehcache-core:2.6.11 (2 usages found) net.sf.ehcache (2 usages found) CacheManager (2 usages found) addCache(String) (1 usage found) 1173 Ehcache clonedDefaultCache = cloneDefaultCache(cacheName); addCacheIfAbsent(String) (1 usage found) 1857 Ehcache clonedDefaultCache = cloneDefaultCache(cacheName); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.