Reputation: 24325
I am trying to get caching working on a Service layer method, but it still goes into it and calls the database. Is my setup wrong?
@Cacheable(cacheName="apiActivitiesCache", keyGenerator = @KeyGenerator (
name = "ListCacheKeyGenerator",
properties = {
@Property( name="useReflection", value="true" ),
@Property( name="checkforCycles", value="true" ),
@Property( name="includeMethod", value="false" )
}
)
)
public GetMemberActivitiesResponse getActivities(GetMemberActivitiesRequest request) {
servlet-context.xml
<ehcache:annotation-driven cache-manager="ehCacheManager" create-missing-caches="true"/>
<ehcache:config cache-manager="ehCacheManager">
<ehcache:evict-expired-elements interval="60" />
</ehcache:config>
<beans:bean id="ehCacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<beans:property name="configLocation" value="/WEB-INF/spring/ehcache.xml"/>
</beans:bean>
ehcache.xml
<?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="apiActivitiesCache" eternal="false"
maxElementsInMemory="100" overflowToDisk="false" diskPersistent="false"
timeToIdleSeconds="0" timeToLiveSeconds="300"
memoryStoreEvictionPolicy="LRU" />
</ehcache>
Upvotes: 0
Views: 1027
Reputation: 462
Is getActivities defined by an interface? Spring uses interface based Java proxies for annotation wrappers so all annotated methods must be defined by an interface.
Upvotes: 0
Reputation: 106
Are you using Ehcache Spring Annotations (http://groups.google.com/group/ehcache-spring-annotations)? This does not work with Hibernate.
Upvotes: 1
Reputation: 549
I tried this with your exact configuration and it worked. Is your service class that has the getActivities method configured as a Spring bean?
Also, is the getActivities method being called by another class, or is it being called by another method in the same class?
Upvotes: 0