2016-01-21 77 views
1

春ehcache不beeing使用

我想为我的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 

我缺少的东西每一个基本在这里?

+0

显示你的缓存配置,你有配置中的@ EnableCaching吗? (或者在使用xml时使用'')。 –

+0

嗨,是的,我使用注释驱动。 <豆类:豆类ID = “CacheManager的” 类= “org.springframework.cache.ehcache.EhCacheCacheManager”> \t \t <豆:属性名= “CacheManager的” REF = “的Ehcache”/> \t \t <! - - 的Ehcache库设置 - > \t <豆:豆ID = “ehcache的” 类= “org.springframework.cache.ehcache.EhCacheManagerFactoryBean”> \t \t <豆:属性名= “configLocation” 值=“类路径:ehcache的.XML “/> \t \t <豆:属性名=” 共享”的值= “真”/> \t – user3420056

+0

不要添加代码评论,将其添加到您的问题。从它看,你只有缓存设置,没有任何相关的启用'@ Cacheable'。 –

回答