我正在使用ehcache。我缓存春@Service方法:EhCache:为什么我的diskStore路径目录没有创建?
@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检索结果存储在缓存中。 我不明白的是我找不到在ehcache.xml中指定的<diskStore path="C:/TEMP/ehcache"/>
。所以我有两个问题:
问题1:为什么没有创建“C:/ TEMP/ehcache”目录?
问题2:缓存我的服务结果在哪里?
感谢您的回答。我改变了maxEntriesLocalHeap =“2”。而且我多次拨打我的服务,但始终没有创建目录。 – Pracede 2014-11-06 13:50:38
从Ehcache 2.6开始,在这种情况下,所有数据都将出现在最低层的磁盘中 - 请参阅[本答案](http://stackoverflow.com/a/23358936/18591) – 2014-11-07 08:43:48