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