Reputation: 189
I have a Spring Rest app with hibernate and MySQL.
The ehcache for a Service work in test and fail in tomcat.
Spring EhCache
<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/cache.xml" />
<property name="shared" value="true" />
</bean>
Context
<cache:annotation-driven />
<context:component-scan base-package="com.example" />
...
<import resource="classpath:spring/spring-cache.xml" />
Cache.xml
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true"
monitoring="autodetect" dynamicConfig="true" maxBytesLocalHeap="150M">
<diskStore path="java.io.tmpdir" />
<cache name="byCategory" eternal="false" diskSpoolBufferSizeMB="20"
timeToIdleSeconds="300" timeToLiveSeconds="600"
memoryStoreEvictionPolicy="LFU" transactionalMode="off">
</cache>
</ehcache>
Hibernate Cache Only in Prod
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.provider_class">net.sf.ehcache.hibernate.EhCacheProvider</prop>
<prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
</prop>
I have a facade with one mtehod has the annotation
@Cacheable(value = { "byCategory" }, key = "#ids.toString()")
This run ok in Test because the hibernate ehcache is not used, but in prod the CacheManager dont load de names that I defined in xml.
Can merge names of hibernate and owns?
Upvotes: 0
Views: 623
Reputation: 14500
You should be able to use multiple CacheManager
in the same application.
Make sure however that they have different names. Given your setup, it might be easiest to test first by naming the CacheManager
you configure using classpath:ehcache/cache.xml
.
Something like the following should do the trick:
<ehcache name="aName"
<!-- Your configuration -->
</ehcache>
Upvotes: 0