我想在春天使用Echcache
mvc。因此對於此使用類似於此的java配置:Spring mvc Ehcache問題
public net.sf.ehcache.CacheManager ehCacheManager() {
net.sf.ehcache.config.Configuration config = new net.sf.ehcache.config.Configuration();
CacheConfiguration cacheConfig = new CacheConfiguration();
cacheConfig.setName("test");
cacheConfig.setMaxEntriesLocalHeap(0);
cacheConfig.setMaxEntriesLocalDisk(10);
cacheConfig.setTimeToLiveSeconds(500);
config.addCache(cacheConfig);
DiskStoreConfiguration diskStoreConfiguration = new DiskStoreConfiguration();
diskStoreConfiguration.setPath("C:/MyCache1");
config.addDiskStore(diskStoreConfiguration);
return net.sf.ehcache.CacheManager.newInstance(config);
}
並用於註解@cachable
用於高速緩存。它工作正常。但所有緩存的數據都保存在內存中。它只創建零大小的test.data
文件。現在我的問題是如何將緩存數據寫入磁盤?
謝謝,我使用'config.persistence(新的PersistenceConfiguration()。strategy(PersistenceConfiguration.Strategy.LOCALTEMPSWAP));'但不工作。 – ali
Strategy.LOCALTEMPSWAP僅用於內存中緩存。如果您想要基於磁盤文件,請使用Strategy.LOCALRESTARTABLE - 注意:LOCALRESTARTABLE持久性功能在企業版Ehcache中可用。 –
那麼爲什麼我不使用彈簧提供程序'ehcache'它寫入磁盤?我的意思是使用'ehcache'方法 – ali