Do caches in ehcache.xml inherit from defaultCache?
Asked Answered
A

2

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)?

Aleut answered 7/6, 2012 at 12:38 Comment(0)
M
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.
Millar answered 7/6, 2012 at 16:11 Comment(2)
I did read that text, but to me it does not seem to be too clear.Aleut
FYI, the defaultCache settings are also used when calling CacheManager#addCacheIfAbsent(String cacheName).Lepidosiren
S
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);
Symbolist answered 14/10, 2019 at 8:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.