cacheDecorator没有刷新Ehcache

时间:2015-03-11 07:18:57

标签: spring caching refresh ehcache

我正在使用ehcache从DB刷新它,但似乎没有刷新。

ehcache.xml文件 - >

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd" 
updateCheck="true"
monitoring="autodetect" 
dynamicConfig="true">

<diskStore path="java.io.tmpdir"/>  

<defaultCache    
    maxElementsInMemory="100"  
    eternal="false"    
    timeToIdleSeconds="120"    
    timeToLiveSeconds="120"    
    overflowToDisk="true"    
    diskSpoolBufferSizeMB="30"    
    maxElementsOnDisk="10000000"    
    diskPersistent="false"    
    diskExpiryThreadIntervalSeconds="120"    
    memoryStoreEvictionPolicy="LRU"/>  

<!-- The cache configuration for our Currency cache -->  
<cache name="cachename"  
    maxElementsInMemory="3000"  
    eternal="false" 
    timeToIdleSeconds="120"  
    timeToLiveSeconds="120"  
    overflowToDisk="true"  
    diskPersistent="false" >
    <persistence strategy="localTempSwap" synchronousWrites="true" />
    <cacheDecoratorFactory class="net.sf.ehcache.constructs.refreshahead.RefreshAheadCacheFactory"
  properties="name=myCacheRefresher,
  timeToRefreshSeconds=180,
  batchSize=10,
  numberOfThreads=4,
  maximumBacklogItems=100,
  evictOnLoadMiss=true" />
</cache>  
</ehcache>  

config.xml中

<ehcache:annotation-driven cache-manager="ehcache" />
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
<property name="cacheManager" ref="ehcache" />
</bean>

<bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" >
<property name="configLocation" value="ehcache.xml" />
</bean>  
<bean id="cachingAttributeSource" class="org.springmodules.cache.annotations.AnnotationCachingAttributeSource" /> 

CatchFetch.java

@GET
@Path("/Mymethod")
@WebMethod(operationName = "mymethodforUI")
public List<Object> mymethodforUI() {

    LOGGER.info("Getting mymethod.");
    return dao.mymethod("keyname");
}

CacheDAO.java

@Cacheable(value = "cachename", key = "#key")
public List<Object> mymethod(String key) {
    List<Object> res -> a slow query getting from Db
    return res;
}

问题1:缓存在前180秒运行良好,但在180秒后,缓存应该刷新。这种行为没有得到反映。有人能找出原因吗?

问题2:当cacheDecoratorFactory定义缓存刷新时,我有什么方法可以记录时间戳吗?

2 个答案:

答案 0 :(得分:0)

您能否确认您没有获得UnsupportedOperationException,说明交易或GAE不支持提前刷新?

答案 1 :(得分:0)

为了提前刷新,您需要cache loader defined。否则,您如何期望缓存知道如何填充映射?

没有加载程序的设置应该抛出异常,因为它不起作用。