ehcache.xml中的缓存是否继承自defaultCache?

时间:2012-06-07 12:38:01

标签: ehcache

如果我有以下配置:

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

缓存timeToIdleSeconds的{​​{1}}值是多少?它是继承自默认缓存,因此等于120,还是采用手册中给出的默认值,即0(无穷大)?

2 个答案:

答案 0 :(得分:14)

timeToIdleSeconds将是默认值,不会从“defaultCache”继承。 “defaultCache”有点用词不当/误导,因为它没有为每个缓存提供“默认值”,但它只是一种为可以/动态添加的缓存指定配置的方法 - 使用cacheManager.addCache(String cacheName) )。

http://www.ehcache.org/ehcache.xml开始,该标记的文档为

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.

答案 1 :(得分: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);