Java EhCache:为什么不创建我的diskStore路径目录?
我在ehcache工作。我正在缓存Spring@Service方法:Java EhCache:为什么不创建我的diskStore路径目录?,java,spring,caching,ehcache,spring-cache,Java,Spring,Caching,Ehcache,Spring Cache,我在ehcache工作。我正在缓存Spring@Service方法: @Service( value = "dataServicesManager" ) @Transactional public class DataServicesManager implements IDataServicesManager{ @Autowired private IDataDAO dataDAO; @Override @Cacheable( value = "alld
@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
}
@Service(value=“dataServicesManager”)
@交易的
公共类DataServicesManager实现IDataServicesManager{
@自动连线
私人爱达多达达道;
@凌驾
@可缓存(value=“alldatas”)
公共列表getAllDatas(整数参数){
//我的逻辑
返回结果;
}
//其他服务
}
以下是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时,该方法被缓存,第二次调用检索结果存储在缓存中。
我不明白的是,我在ehcache.xml中找不到指定的
。所以我有两个问题:
问题1:为什么不创建“C:/TEMP/ehcache”目录
问题2:我的服务结果缓存在哪里?可能是因为您检索到的数据没有溢出到磁盘。缓存在内存中完成,直到超过某个阈值。尝试将maxEntriesLocalHeap减小到您知道的足够小的程度,以使您的数据溢出,并查看文件是否已创建。您的Ehcache配置是罪魁祸首
defaultCache
元素仅在以编程方式创建缓存而不指定配置时使用
<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>
但是您可以明确定义所有数据
缓存,而不使用任何磁盘选项
因此,您的配置需要:
<cache name="alldatas" maxEntriesLocalHeap="10000" eternal="false"
timeToIdleSeconds="21600" timeToLiveSeconds="21600" memoryStoreEvictionPolicy="LRU"
overflowToDisk="true"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120">
</cache>
然后这个缓存将使用磁盘存储
如果您不打算在应用程序中使用其他缓存,也可以删除
defaultCache
元素,以保持清晰。谢谢您的回答。我更改了maxEntriesLocalHeap=“2”。我多次调用我的服务,但始终没有创建目录。从Ehcache 2.6开始,所有数据都将出现在最低层,即本例中的磁盘中-请参阅