java - Spring ehcache 未被使用

标签 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>

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/

相关文章:

android - 我什么时候应该在 android 中使用内容提供程序

Java HashMap之HashMap vs HashMap之String

java - 颜色引用不好?

java - 如何在使用 iText 创建的 PDF 中显示阿拉伯语

java - 基本路径使用异常 : Cannot join to attribute of basic type

javascript - 如何在表单提交后添加成功通知

php - 304 : Not modified and front end caching

c# - 如何在 Entity Framework 7 中重新加载模型?

java - com.fasterxml.jackson.databind.ser.BeanSerializer.serialize Spring JPA

具有多个 View 解析器的 Spring MVC