缓存不适用于地图

caching not working for map

Java - Spring - ehcache

有以下代码来实现 eh-cache 非常适合对象列表,但是当我尝试缓存地图时它总是尝试加载新副本...缓存是否不适用于地图?任何帮助表示赞赏。

Spring配置

@Bean
public CacheManager cacheManager() {
    return new EhCacheCacheManager(ehCacheCacheManager().getObject());
}

@Bean
public EhCacheManagerFactoryBean ehCacheCacheManager() {
    EhCacheManagerFactoryBean cmfb = new EhCacheManagerFactoryBean();
    cmfb.setConfigLocation(new ClassPathResource("ehcache.xml"));
    cmfb.setShared(true);
    return cmfb;
}


<!-- ehcache entry -->
    <cache name="serviceMapCache" 
        maxEntriesLocalHeap="5000"
        maxEntriesLocalDisk="50000" 
        eternal="false" 
        diskSpoolBufferSizeMB="20"
        timeToLiveSeconds="10800" 
        memoryStoreEvictionPolicy="LFU" 
        transactionalMode="off">
        <persistence strategy="localTempSwap" />
    </cache>

用法

@Cacheable(value=CacheNames.SERVICE_MAP_CACHE)
public Map<String, Service> getAllServicesToMap(){
 // load map 
 // return map
 }

因为你想使用磁盘存储,你需要确保你缓存的对象是Serializable。 对于您的地图示例,它表示地图本身、它包含的键和值。