spring - Ehcache没有被cacheDecorator刷新

标签 spring caching refresh ehcache

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

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>  

配置.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 秒后,缓存应该刷新。这种行为没有得到反射(reflect)。有人能找出原因吗?

问题2:有什么方法可以记录由cacheDecoratorFactory定义的缓存刷新发生时的时间戳吗?

最佳答案

您能否确认您没有收到 UnsupportedOperationException,指出事务或 GAE 不支持刷新?

关于spring - Ehcache没有被cacheDecorator刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28980677/

相关文章:

java - 如何编写一个cron表达式或设置一个在Spring中只执行一次的计时器?

caching - 在 getters/setters 中缓存?

caching - MySQL 查询缓存 : limited to a maximum cache size of 128 MB?

javascript - 使用 jQuery/Javascript 防止任何形式的页面刷新

java - 除非在 DAO 内部,否则交易无法进行

java - 带有 Hibernate 的 Spring - 线程 "main"java.lang.NullPointerException 中的异常

spring - 如何在 Spring 中使用 javax.validation.constraints 验证 List 内元素的长度

javascript - 缓存 html .load 结果以加快加载速度

matlab - 如何在matlab中更新变量?

php - 浏览器是否总是使用带有 .html 扩展名的缓存版本的页面?