Announcement Announcement Module
Collapse
No announcement yet.
Cacheable working or no? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Cacheable working or no?

    I'm trying to implement caching on my application. I've added the annotation on my concrete class method.

    public GroupService implements IGroupService{
    @Cacheable(value="groups", key="#gid")
    public Group getGroup(int gid) throws DataAccessException {
    //Get the group information
    return groupDAO.getGroup(gid);
    }
    }

    In my applicationContext.xml, I've added the proper

    <cache:annotation-driven />
    <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCa cheManager" p:cache-manager-ref="ehcache" />
    <bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheMa nagerFactoryBean" p:config-location="classpath:ehcache.xml" />

    In my ehcache.xml, I've configured my groups cache to
    <?xml version="1.0" encoding="UTF-8"?>
    <ehcache>

    <defaultCache
    maxElementsInMemory="50"
    eternal="false"
    overflowToDisk="true"
    diskPersistent="true"
    memoryStoreEvictionPolicy="LFU" />

    <cache name="groups"
    maxElementsInMemory="20"
    eternal="false"
    overflowToDisk="true"
    diskPersistent="true"
    memoryStoreEvictionPolicy="LFU" />

    </ehcache>

    When I trigger a call to the my GroupService:getGroup, the method seems to be called (if I set a breakpoint there, the breakpoint is hit.) I thought with the Cacheable annotation, if I've called that method before using the same parameter, it would use the cache value instead. Am I incorrect? How do you verify that the caching is working?

  • #2
    This question is probably a better candidate for StackOverflow, perhaps with the "spring" and "spring-cache" tags.

    Could you post your question there?
    The forums are moving to stackoverflow, a page explaining all this will be available there in a few days: http://spring.io/questions

    Comment

    Working...
    X