Announcement Announcement Module
Collapse

Spring Modules forum decommissioned in favor of Spring Extensions

As the Spring Modules project has been replaced by the Spring Extensions (http://www.springsource.org/extensions) project, this forum has been decommissioned in favour of Spring Extensions one at:
http://forum.springsource.org/forumdisplay.php?f=44

Please see the Spring Extensions home page for a complete list of current projects in Java, .NET and ActionScript. You can also propose one if you want.

Cheers,
Costin Leau
SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
http://twitter.com/costinl
See more
See less
ehcache not intercepting method calls - what am I doing wrong? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ehcache not intercepting method calls - what am I doing wrong?

    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:

    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>
    ehcache.xml is configured as follows:
    Code:
    <cache name="firstCache" maxElementsInMemory="1" eternal="true" overflowToDisk="true" diskPersistent="true" />
    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:
    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();
    	}
    }
    Here is the output that 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 ]
    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:

    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
Working...
X