Подтвердить что ты не робот

Делают ли кэши в ehcache.xml наследованием от defaultCache?

Если у меня есть следующая конфигурация:

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

Каким будет значение timeToIdleSeconds для кеша test? Будет ли он унаследован от кеша по умолчанию и, следовательно, будет равен 120, или он примет значение по умолчанию, указанное в руководстве, которое равно 0 (бесконечность)?

4b9b3361

Ответ 1

Значение 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.

Ответ 2

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