gpt4 book ai didi

java - 缓存 : Why my diskStore path directory is not created?

转载 作者:搜寻专家 更新时间:2023-11-01 03:22:27 25 4
gpt4 key购买 nike

我正在使用 ehcache。我正在缓存 Spring @Service 方法:

@Service( value = "dataServicesManager" )
@Transactional
public class DataServicesManager implements IDataServicesManager{

@Autowired
private IDataDAO dataDAO;



@Override
@Cacheable( value = "alldatas" )
public List<Data> getAllDatas(Integer param) {

// my logic

return results;

}
// others services
}

这是 Spring 配置片段:

 <cache:annotation-driven/>

<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="WEB-INF/ehcache.xml"/>
<property name="shared" value="true"/>
</bean>

这是我的 ehcache 配置。

<ehcache xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true" monitoring="autodetect" dynamicConfig="true">

<diskStore path="C:/TEMP/ehcache"/>

<defaultCache eternal="false"
timeToIdleSeconds="300"
timeToLiveSeconds="1200"
overflowToDisk="true"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120" />

<cache name="alldatas" maxEntriesLocalHeap="10000" eternal="false"
timeToIdleSeconds="21600" timeToLiveSeconds="21600" memoryStoreEvictionPolicy="LRU">

</cache>

</ehcache>

当我从 Spring @Controller 调用服务方法 getAllDatas 时,该方法被缓存,第二次调用检索缓存中的结果存储。我不明白的是我找不到 <diskStore path="C:/TEMP/ehcache"/>在 ehcache.xml 中指定。所以我有两个问题:

问题1:为什么没有创建“C:/TEMP/ehcache”目录?

问题2:我的服务结果缓存在哪里?

最佳答案

你的 Ehcache 配置是罪魁祸首。

defaultCache 元素仅在您以编程方式创建缓存而不指定配置时使用。

但是您明确定义了您的 alldatas 缓存,没有任何磁盘选项。

所以你的配置需要变成:

<cache name="alldatas" maxEntriesLocalHeap="10000" eternal="false"
timeToIdleSeconds="21600" timeToLiveSeconds="21600" memoryStoreEvictionPolicy="LRU"
overflowToDisk="true"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120">

</cache>

然后这个缓存将使用磁盘存储。

如果您不打算在您的应用程序中使用其他缓存,为了清楚起见,您还可以删除 defaultCache 元素。

关于java - 缓存 : Why my diskStore path directory is not created?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26777627/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com