我正在尝试为我的 MVC 页面设置一个简单的 Spring 缓存 ehcache。但似乎从来没有使用过缓存。我的函数每次都会执行。
@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 配置文件
@DynamoDBTable(tableName="ProcessedDocuments")
public class ProcessedDocument implements Serializable {
//Just contains some simple get and set methods.
}
每次执行 getDocuments 时,它都会调用数据库并输出一个新的“getDocumetns!” + 控制台中的 DateTime.now()。
我在调试中看到的唯一“奇怪”的是
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
我在这里错过了一些基本的东西吗?
最佳答案
我找到了你并用谷歌搜索了它。我从 Mkyong Ehcache 示例中找到了一个示例;
http://www.mkyong.com/spring/spring-caching-and-ehcache-example/
我认为这对你有用。因为您的 ehcache.xml: 不相似 Mkyong 的示例 ehcache.xml。
希望对你有用..
关于java - Spring ehcache 未被使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34926675/