2016-01-21 74 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'。 –

回答