首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ehcache未被cacheDecorator刷新

Ehcache未被cacheDecorator刷新
EN

Stack Overflow用户
提问于 2015-03-11 15:18:57
回答 2查看 367关注 0票数 3

我正在使用ehcache从数据库中刷新它,但它似乎没有被刷新。

ehcache.xml文件->

代码语言:javascript
复制
<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

代码语言:javascript
复制
<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

代码语言:javascript
复制
@GET
@Path("/Mymethod")
@WebMethod(operationName = "mymethodforUI")
public List<Object> mymethodforUI() {

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

CacheDAO.java

代码语言:javascript
复制
@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定义的缓存刷新发生时的时间戳?

EN

回答 2

Stack Overflow用户

发布于 2015-03-11 17:48:58

您能确认您没有收到UnsupportedOperationException,说明在事务或使用GAE时不支持预刷新吗?

票数 0
EN

Stack Overflow用户

发布于 2015-03-13 00:32:28

为了让刷新提前工作,你需要有一个cache loader defined。否则,如何期望缓存知道如何填充映射呢?

没有加载器的设置可能会抛出一个异常,因为它将无法工作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28980677

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档