In my application I have included the following xml configuration for EhCache (version 2.4.3 of ehcache-core)
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd"
updateCheck="false"
monitoring="autodetect"
dynamicConfig="true">
<defaultCache
eternal="false"
timeToIdleSeconds="0"
timeToLiveSeconds="0">
</defaultCache>
<cache name="MyParamsCache"
eternal="true"
overflowToDisk="true"
diskSpoolBufferSizeMB="20"
memoryStoreEvictionPolicy="LRU"
statistics="true">
</cache>
</ehcache>
Cache manager is declared as
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
<property name="cacheManager" ref="ehcache" />
</bean>
<bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="classpath:ehcache.xml" />
</bean>
Using a bean I add parameters to this cache (by autowiring the cacheManager in Spring). There is no error in the application, but when I check the caches in JavaMelody (Data cashes section), I see that MyParamsCache
appears twice. One instance is filled with content, while the other one is empty.
Does anyone have any idea why MyParamsCache
appears twice and how to remove the dummy instance?
EDITED
I also have hibernate second level cache in persistence.xml. The cache bean is created again there, instead of using the already existing one. The code is
<persistence-unit name="myPU">
.....
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServer2008Dialect" />
<property name="hibernate.hbm2ddl.auto" value="validate" />
<property name="hibernate.cache.use_second_level_cache" value="true" />
<property name="hibernate.cache.use_query_cache" value="true" />
<property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.EhCacheRegionFactory" />
</properties>
</persistence-unit>