Infinispan相当于ehcache的copyOnRead和copyOnWrite

发布于 2024-11-30 23:37:20 字数 642 浏览 5 评论 0原文

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

我喜欢 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));
}

I am planning to implement a cache solution into an existing web app. Nothing complicated: basically a concurrent map that supports overflowing to disk and automatic eviction. Clustering the cache could be requirement in the future, but not now.

I like ehcache's copyOnRead and copyOnWrite features, because it means that I don't have to manually clone things before modifying something I take out of the cache. Now I have started to look at Infinispan, but I have not found anything equivalent there. Does it exist?

I.e., the following unit tests should pass:

@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));
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

ぇ气 2024-12-07 23:37:20

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

Infinispan does support copyOnRead/copyOnWrite, albeit the actual format isn't pluggable. The configuration element is lazyDeserialization in Infinispan 4.x and storeAsBinary in Infinispan 5.x. Objects are serialized using the pluggable Marshaller framework, which is used for all forms of marshalling including for RPC calls over a network and storage to disk.

月牙弯弯 2024-12-07 23:37:20

据 JBoss 开发人员称,Infinispan 尚不支持此类功能。您应该在Infinispan问题跟踪器中记录增强请求,以便其他人可以对其进行投票(我会的) 。

话虽这么说,如果您现在需要此功能,解决方法是扩展 AbstractDelegatingCache,并重写 getput 方法来添加此功能。您可以使用自己的复制策略或查看 EHCache 的做法以获得灵感。

另外,如果您还有其他问题,可以考虑Infinispan 论坛,因为您将会有来自 Infinispan 社区的更多意见。

According to a JBoss developer, Infinispan does not yet support such feature. You should log a request for enhancement in the Infinispan issue tracker, so that others may vote on it (I will).

That being said, if you need this feature now, a workaround would be to extend AbstractDelegatingCache, and override the get and put methods to add this functionality. You could use your own copy strategy or look at how EHCache did it for inspiration.

Also, you may consider the Infinispan forum if you have further questions, since you will have more views from the Infinispan community.

迷途知返 2024-12-07 23:37:20

我相信storeAsBinary仅在对象需要序列化时才生效,这意味着当调用put操作时,所有者不是当前节点。

这也意味着如果键 0 的所有者不是当前节点,问题中的测试用例可以通过,但如果是单节点环境,它仍然会失败。

I believe storeAsBinary only takes effect when objects need to be serialized which means when a put operation is called, the owner is not the current node.

This also means the testcases in the question could pass if the owner of key 0 is not the current node, but it would still fail if it's a single node environment.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文