Hello,
I tried to add some ehcache to my webapp.
I have read severals tutorials and documentation. All seems in place, with no error everything running fine except that everytime I hit F5 I see that the cached method is executed like if there were no cache:
application context :
ehcache :Code:<cache:annotation-driven /> <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager" p:cache-manager-ref="ehcache"/> <bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" p:config-location="classpath:ehcache.xml"/>
Code:<?xml version="1.0" encoding="UTF-8"?> <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"> <!-- <defaultCache eternal="true" maxElementsInMemory="100" overflowToDisk="false" /> <cache name="myCache" maxElementsInMemory="40" eternal="true" overflowToDisk="false" /> --> <diskStore path="java.io.tmpdir"/> <cache name="myCache" maxElementsInMemory="100" eternal="false" timeToIdleSeconds="1200" timeToLiveSeconds="1200" overflowToDisk="true" maxElementsOnDisk="10000000" diskPersistent="false" diskExpiryThreadIntervalSeconds="1200" memoryStoreEvictionPolicy="LRU"/> </ehcache>
My controller looks like this
Code:@Controller @RequestMapping("/mypage") public class MyController { @Cacheable(value ="myCache", key="locale") public MyObject getMyObject(Locale locale){ Logger l = Logger.getLogger(this.getClass()); l.error("calling getMyObject"); ... } @RequestMapping public String index(ModelMap model, Locale locale) { ... a = getMyObject(locale); ... } }
everytime I hit f5 I can see in the log :
"calling getMyObject"
When I guess, I should see it only the first time ? or maybe I am wrong somewhere ?
Thanks for help !


Reply With Quote