I am trying to cache the results of getAccountProxy method in my AccountProxyManager class. It seems that the calls are never intercepted. Here is what I have in applicationContext.xml:
ehcache.xml is configured as follows:Code:<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"> <property name="configLocation"> <value>classpath:ehcache.xml</value> </property> </bean> <bean id="cacheableTarget" class="irrelevant.proxy.AccountProxyManager"> <property name="cacheManager"> <ref bean="cacheManager" /> </property> <property name="cacheName"> <value>firstCache</value> </property> </bean> <bean id="cacheProvider" class="org.springmodules.cache.provider.ehcache.EhCacheFacade"> <property name="cacheManager" ref="cacheManager" /> <property name="cacheProfiles"> <props> <prop key="first">[cacheName=firstCache]</prop> </props> </property> </bean> <bean id="cacheable" class="org.springmodules.cache.interceptor.proxy.CacheProxyFactoryBean"> <property name="cacheProviderFacade" ref="cacheProvider" /> <property name="cachingAttributes"> <props> <prop key="get*">[cacheProfileId=first]</prop> </props> </property> <property name="cacheFlushAttributes"> <props> <prop key="set*">[cacheProfileIds=first][flushBeforeExecution=true]</prop> </props> </property> <property name="target" ref="cacheableTarget" /> </bean>
I do not see any changes in firstCache.data or firstCache.index as I run the server. A call to getAccountProxy is inside onMessage of an MDB:Code:<cache name="firstCache" maxElementsInMemory="1" eternal="true" overflowToDisk="true" diskPersistent="true" />
Here is the output that I see:Code:protected void onEjbCreate() { this.setAccountProxyMngr((AccountProxyManager)this.getBeanFactory().getBean("cacheableTarget")); } public AccountProxyManagerIF getAccountProxyMngr() { return accountProxyMngr; } public void setAccountProxyMngr(AccountProxyManager manager) { accountProxyMngr = manager; } public void onMessage(javax.jms.Message msg) { try { JMSMapMessage mapMsg = (JMSMapMessage)msg; String accountNumber = mapMsg.getString(ACCT_NO); AccountProxy acctProxy = this.getAccountProxyMngr().getAccountProxy(accountNumber); //... skip System.out.println("Cache: " + this.getAccountProxyMngr().getCacheManager().getCache("firstCache").toString()); List cacheKeys = this.getAccountProxyMngr().getCacheManager().getCache("firstCache").getKeys(); Iterator itr = cacheKeys.iterator(); while (itr.hasNext()) { System.out.println("firstCache key: " + itr.next()); } } catch (Exception e) { e.printStackTrace(); } }
It does not change when new JMS messages are received on the Topic it is listening on. I have tried declaring accountProxyMngr both as AccountProxyManager and AccountProxyManagerIF (interface) and adjusted getAccountProxyMngr, setAccountProxyMngr and the casting accordingly. During initialization (among other things) I see:Cache: [ name = firstCache status = 2 eternal = true overflowToDisk = true maxElementsInMemory = 1 timeToLiveSeconds = 0 timeToIdleSeconds = 0 diskPersistent = true diskExpiryThreadIntervalSeconds = 120 hitCount = 0 memoryStoreHitCount = 0 diskStoreHitCount = 0 missCountNotFound = 0 missCountExpired = 0 ]
EhCacheManage I org.springframework.cache.ehcache.EhCacheManagerFa ctoryBean Initializing EHCache CacheManager
DefaultListab I org.springframework.beans.factory.support.DefaultL istableBeanFactory Creating shared instance of singleton bean 'cacheableTarget'
DefaultListab I org.springframework.beans.factory.support.DefaultL istableBeanFactory Creating shared instance of singleton bean 'cacheProvider'
DefaultListab I org.springframework.beans.factory.support.DefaultL istableBeanFactory Creating shared instance of singleton bean 'cacheable'
DefaultAopPro I org.springframework.aop.framework.DefaultAopProxyF actory CGLIB2 available: proxyTargetClass feature enabled


