Infinispan相当于ehcache的copyOnRead和copyOnWrite

wax*_*ing 4 java caching ehcache infinispan

我计划在现有的Web应用程序中实现缓存解决方案.没有什么复杂的:基本上是支持溢出到磁盘和自动驱逐的并发映射.未来可能需要对缓存进行群集,但现在不需要.

我喜欢ehcache的copyOnRead和copyOnWrite功能,因为这意味着在修改我从缓存中取出的内容之前,我不必手动克隆内容.现在我已经开始关注Infinispan了,但我还没有找到相应的东西.它存在吗?

即,以下单元测试应通过:

@Test
public void testCopyOnWrite() {
    Date date = new Date(0);
    cache.put(0, date);
    date.setTime(1000);
    date = cache.get(0);
    assertEquals(0, date.getTime());
}

@Test
public void testCopyOnRead() {
    Date date = new Date(0);
    cache.put(0, date);
    assertNotSame(cache.get(0), cache.get(0));
}
Run Code Online (Sandbox Code Playgroud)

小智 7

Infinispan 确实支持copyOnRead/copyOnWrite,尽管实际格式不可插拔.配置元件是lazyDeserialization在Infinispan的4.x和storeAsBinary在Infinispan的5.x的 使用可插入的Marshaller框架序列化对象,该框架用于所有形式的编组,包括通过网络进行RPC调用和存储到磁盘.