我正在使用 ehcache 将数据保存在磁盘上,以便 JVM 重新启动。由于数据很大,所以想尝试一下BigMemory Go产品。 但在他们的文档中我没有找到任何关于磁盘配置(最大大小、路径)的提及。 使用 ehcache 我的配置如下所示:
PersistentCacheManager persistentCacheManager =
newCacheManagerBuilder()
.with(persistence(new File("path_to_cache_dest"))
.withCache("myType"), newCacheConfigurationBuilder(String.class, String.class, newResourcePoolsBuilder()
.disk(2, MemoryUnit.GB, true))
.build(true);
BigMemory Go 中的等效项是什么? BigMemory 中处理磁盘持久化的对象是什么?代码示例会很棒。
最佳答案
BigMemory Go是基于Ehcache 2.x的商业产品。因此,它与 Ehcache 3.x 无关,因为它使用不同的代码库和不同的 API。
因此,您需要配置 Ehcache 2.x 以实现磁盘持久性,然后使用商业版本运行该配置,然后商业版本将使用商业磁盘存储:
new CacheManager(new Configuration()
.cache(new CacheConfiguration("aCache", 10000)
.persistence(new PersistenceConfiguration().strategy(PersistenceConfiguration.Strategy.LOCALRESTARTABLE))
.maxBytesLocalDisk(2, MemoryUnit.GB)
.timeToLiveSeconds(1000)
.timeToLiveSeconds(360))
.name("testDiskStoreSize")
.diskStore(new DiskStoreConfiguration().path("java.io.tmpdir/testDiskStoreSize")));
请注意,如果您要将 Strategy.LOCALRESTARTABLE
替换为 Strategy.LOCALTEMPSWAP
,上述内容在开源中仍然有效。您只会失去防崩溃重启能力并使用不同的磁盘存储模型。
关于java - 如何配置BigMemory进行磁盘持久化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46784582/