【问题标题】:Ehcache is not being refreshed by cacheDecoratorEhcache 没有被 cacheDecorator 刷新
【发布时间】:2015-05-12 21:24:21
【问题描述】:

我正在使用 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>  

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 定义的缓存刷新发生时记录时间戳?

【问题讨论】:

    标签: spring caching refresh ehcache


    【解决方案1】:

    您能否确认您没有收到 UnsupportedOperationException 说明事务或 GAE 不支持预刷新?

    【讨论】:

    • 不,我不会得到 UnsupportedOperationException
    • 您使用的是哪个版本的 ehcache?似乎 diskPersistent 在最近的版本中已被弃用,我看到 diskPersistent="false" > 都令人困惑
    【解决方案2】:

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

    没有加载器的设置可能会抛出异常,因为它不起作用。

    【讨论】:

      猜你喜欢
      • 2017-06-25
      • 2010-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-22
      • 2012-02-05
      相关资源
      最近更新 更多