David He
David He

Reputation: 394

EHcache does not work in spring

I am now applying EHcache to my web application by means of SpringModules EHcache support.

However, it does not work. No exception thrown though.

ehcache.xml:

<ehcache>
  <diskStore path="c:\\myapp\\cache"/>
  <defaultCache
      maxElementsInMemory="500"
      eternal="true"
      overflowToDisk="false"
      memoryStoreEvictionPolicy="LFU" />
  <cache name="WorldExpoCache"
      maxElementsInMemory="500"
      eternal="true"
      overflowToDisk="false"
      memoryStoreEvictionPolicy="LFU" />
</ehcache>

Excerpt of my applicationContext.xml:

<!-- EHCache configuration -->
    <ehcache:config configLocation="classpath:ehcache.xml"/>   

<ehcache:proxy id="WorExpoDAO" refId="worldExpoDAO"> 
       <ehcache:caching methodName="grabcategory" cacheName="WorldExpoCache"/>  
    </ehcache:proxy>

    <bean id="worldExpoDAO" class="com.cn.dao.WorldExpoDAOImpl">
        <property name="sessionFactory">
            <ref local="mySessionFactory" />
        </property>
    </bean>

Certainly, I have a method called "grabcategory" sitting in my DAO class. However, when this method fired up second time, related data was still retrieved from underlying database rather than from cache.

P.S.: I did include all required jars into my application

Why was that? Can anybody tell me where I did wrong?

Any suggestions will be highly appreciated.

Upvotes: 1

Views: 3080

Answers (3)

matsev
matsev

Reputation: 33759

The @Cachable annotation was introduced in the Spring 3.1 release. It can be configured to use Ehcache as backend.

Upvotes: 1

Steve Westwood
Steve Westwood

Reputation: 43

In fact the caching functionality of Spring Modules does have a replacement. EhCache Annotations for Spring has emerged, and is in fact a lot easier to use.

http://code.google.com/p/ehcache-spring-annotations/

Upvotes: 1

skaffman
skaffman

Reputation: 403481

Spring Modules is no longer maintained, and does not work properly with the current versions of Spring and EhCache.

Unfortunately, the caching functionality provided by Spring Modules doesn't really have a replacement, you'll have to roll your own.

Upvotes: 1

Related Questions