Infinispan相当于ehcache的copyOnRead和copyOnWrite [英] Infinispan equivalent to ehcache's copyOnRead and copyOnWrite

查看:177
本文介绍了Infinispan相当于ehcache的copyOnRead和copyOnWrite的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我计划在现有的Web应用程序中实施缓存解决方案。没什么复杂的:基本上是一个并发映射,它支持溢出到磁盘和自动逐出。

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.

我喜欢ehcache的copyOnRead和copyOnWrite功能,因为这意味着我不必手动克隆东西。在修改某些东西之前,我要从缓存中取出。现在,我开始查看 Infinispan ,但是我在那里没有找到任何等效的东西。它存在吗?

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


推荐答案

根据JBoss开发人员, 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).

话虽如此,如果您现在现在需要此功能,一种解决方法是扩展 AbstractDelegatingCache ,并覆盖 get 放置方法以添加此功能。您可以使用自己的复制策略,或者看看EHCache是​​如何获得灵感的。

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.

此外,您还可以考虑 Infinispan论坛如果您还有其他问题,因为您将在Infinispan社区获得更多的意见。

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

这篇关于Infinispan相当于ehcache的copyOnRead和copyOnWrite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆