I'm trying to setup a simple Spring cache ehcache for my MVC page. But it seems that the cache is never used. My function is executed each time.
@Cacheable(value="newsDocuments",key="#category")
public List<ProcessedDocument> getDocuments(String category, int limit){
List<ProcessedDocument> list = new ArrayList<ProcessedDocument>();
System.out.println("getDocumetns!" + DateTime.now());
list = getDBStuff(category,limit);
return list;
}
ehcache.xml
<?xml version="1.0" encoding="UTF-8"?>
<ehcache>
<diskStore path="java.io.tmpdir" />
<defaultCache maxElementsInMemory="100" eternal="false"
timeToIdleSeconds="10000" timeToLiveSeconds="60000" overflowToDisk="false" />
<cache name="newsDocuments" timeToIdleSeconds="10000" timeToLiveSeconds="60000" maxElementsInMemory="10" eternal="false" overflowToDisk="false" />
</ehcache>
spring config file
@DynamoDBTable(tableName="ProcessedDocuments")
public class ProcessedDocument implements Serializable {
//Just contains some simple get and set methods.
}
Each time getDocuments is being executed, it calls the db and outputs a new "getDocumetns!" + DateTime.now() in the console.
The only "strange" I see in the debug is
DEBUG: net.sf.ehcache.config.ConfigurationHelper - CacheDecoratorFactory not configured. Skipping for 'newsDocuments'.
DEBUG: net.sf.ehcache.config.ConfigurationHelper - CacheDecoratorFactory not configured for defaultCache. Skipping for 'newsDocuments'.
INFO : org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'mvc-dispatcher': initialization completed in 875 ms
Am I missing something every basic here?
I looked for you and googled it .I found an example from Mkyong Ehcache example ;
http://www.mkyong.com/spring/spring-caching-and-ehcache-example/
and I think it will useful for you. Because your ehcache.xml: not similar Mkyong's example ehcache.xml.
I hope it will be useful for you..
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.