春天ehcache没有使用

时间:2016-01-21 14:39:22

标签: java spring-mvc caching ehcache spring-cache

我正在尝试为我的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>

弹簧配置文件

              

    @DynamoDBTable(tableName="ProcessedDocuments")
public class ProcessedDocument implements Serializable {
//Just contains some simple get and set methods.
}

每次执行getDocuments时,它都会调用db并输出一个新的“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

我错过了每个基本的东西吗?

1 个答案:

答案 0 :(得分:0)

我找了你并用Google搜索。我从Mkyong Ehcache的例子中找到了一个例子;

http://www.mkyong.com/spring/spring-caching-and-ehcache-example/

我觉得它对你有用。因为你的 ehcache.xml:不相似 Mkyong的例子是ehcache.xml。

我希望它对你有用..