Java 集群共享缓存

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/982251/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 21:51:40  来源:igfitidea点击:

Cluster Shared Cache

javacachingdistributed-computingcluster-computing

提问by GuiSim

I am searching for a java framework that would allow me to share a cache between multiple JVMs.

我正在寻找一个允许我在多个 JVM 之间共享缓存的 Java 框架。

What I would need is something like Hazelcastbut without the "distributed" part. I want to be able to add an item in the cache and have it automatically synced to the other "group member" cache. If possible, I'd like the cache to be sync'd via a reliable multicast (or something similar).

我需要的是Hazelcast 之类的东西,但没有“分布式”部分。我希望能够在缓存中添加一个项目并让它自动同步到另一个“组成员”缓存。如果可能,我希望通过可靠的多播(或类似的东西)同步缓存。

I've looked at Shoalbut sadly the "Distributed State Cache" seems like an insufficient implementation for my needs.

我看过Shoal,但遗憾的是“分布式状态缓存”似乎不足以满足我的需求。

I've looked at JBoss Cachebut it seems a little overkill for what I need to do.

我看过JBoss Cache,但对于我需要做的事情来说似乎有点矫枉过正。

I've looked at JGroups, which seems to be the most promising tool for what I need to do. Does anyone have experiences with JGroups ? Preferably if it was used as a shared cache ?

我看过JGroups,它似乎是我需要做的最有前途的工具。有没有人有使用 JGroups 的经验?最好将其用作共享缓存?

Any other suggestions ?

还有其他建议吗?

Thanks !

谢谢 !

EDIT: We're starting tests to help us decide between Hazelcast and Infinispan, I'll accept an answer soon.

编辑:我们正在开始测试以帮助我们在 Hazelcast 和 Infinispan 之间做出决定,我很快就会接受答案。

EDIT: Due to a sudden requirements changes, we don't need a distributed map anymore. We'll be using JGroups for a low level signaling framework. Thanks everyone for you help.

编辑:由于突然的需求变化,我们不再需要分布式地图。我们将使用 JGroups 作为低级信号框架。谢谢大家的帮助。

采纳答案by GuiSim

After some more searching, I found JGroup's ReplicatedHashMap. It has not been thoroughly tested but it seems like an excellent start. It fills all my requirements without giving me too much features I don't need. It's also quite flexible. I'm still searching for the "perfect" answer though :)

经过更多搜索,我找到了JGroup 的 ReplicatedHashMap。它尚未经过彻底测试,但似乎是一个很好的开始。它满足了我的所有要求,而没有给我太多我不需要的功能。它也非常灵活。不过,我仍在寻找“完美”的答案:)

Thanks for your answers.

感谢您的回答。

回答by John Meagher

回答by Dan Gravell

Have you considered Terracotta? Might be overkill: http://www.terracotta.org/web/display/orgsite/Data+Caching

你考虑过兵马俑吗?可能有点矫枉过正:http: //www.terracotta.org/web/display/orgsite/Data+Caching

There was a JSR in the area of caching a while ago, do any of the following fit the bill: http://java-source.net/open-source/cache-solutions/jcache?

不久前在缓存领域有一个 JSR,请执行以下任何一项:http://java-source.net/open-source/cache-solutions/jcache

I personally used FKache a few years ago and it worked well, but I didn't use it in distributed mode.

几年前我个人使用过 FKache,效果很好,但我没有在分布式模式下使用它。

Is it important that it's a distributed cache with local copies of data? There's also the JavaSpaces stuff if it's shared memory you need...

它是具有本地数据副本的分布式缓存是否重要?如果您需要共享内存,还有 JavaSpaces 的东西......

回答by victor hugo

My option is Java Caching Systemfrom Apache, it has support of TCP Lateral Cache which in my opinion is the feature you need.

我的选择是Apache 的Java 缓存系统,它支持 TCP 横向缓存,我认为这是您需要的功能。

回答by Talip Ozturk

How about this?

这个怎么样?

Have a local ConcurrentHashMap as your local cache. Create a Hazelcast distributed map/cache. Start listening for the distributed map events and update your local ConcurrentHashMap.

将本地 ConcurrentHashMap 作为本地缓存。创建 Hazelcast 分布式地图/缓存。开始侦听分布式地图事件并更新您的本地 ConcurrentHashMap。

Now local caches on each member will be the same. Auto-synched.

现在每个成员上的本地缓存将是相同的。自动同步。

import com.hazelcast.core.IMap; 
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.EntryListener;
import com.hazelcast.core.EntryEvent; 
import java.util.concurrent.ConcurrentHashMap;

public class Sample implements EntryListener {
        Map localCache = new ConcurrentHashMap ();

        public static void main(String[] args) { 
                Sample sample = new Sample();
                IMap   map    = Hazelcast.getMap("default"); 

                //Listen for all added/updated/removed entries
                map.addEntryListener(sample, true);  
        }

        public void entryAdded(EntryEvent event) {
             localCache.put(event.getKey(), event.getValue());            
        }

        public void entryRemoved(EntryEvent event) {
             localCache.remove(event.getKey());            
        }

        public void entryUpdated(EntryEvent event) {
             localCache.put(event.getKey(), event.getValue());            
        }
}

回答by Hardy

Have you considered Infinispan - http://www.jboss.org/infinispan/? The API is very simple and based on a standard (JSR-107). The usage is also very simple

你考虑过 Infinispan - http://www.jboss.org/infinispan/吗?API 非常简单并且基于标准 (JSR-107)。用法也很简单

CacheManager manager = new DefaultCacheManager(
                GlobalConfiguration.getClusteredDefault() );

Cache cache = manager.getCache();

cache.put("key", "value");

--Hardy

——哈代

回答by skaffman

I've used a few technologies in this area, I can highly recommend JBoss Cacheas the best choice for what you're trying to do. It uses JGroups as its transport, but provides a higher-level transactional abstraction. Out-of-the-box it gives you a distributed tree-node structure.

我在这方面使用了一些技术,我强烈推荐JBoss Cache作为您尝试做的事情的最佳选择。它使用 JGroups 作为其传输,但提供更高级别的事务抽象。开箱即用的它为您提供分布式树节点结构。

edit: Oh, and JBossCache is independent of JBoss Application Server, you can use it in any environment. If anything, it works better outside of JBossAS than it does inside it.

编辑:哦,JBossCache 独立于 JBoss 应用服务器,你可以在任何环境中使用它。如果有的话,它在 JBossAS 外部比在内部工作得更好。

回答by Andrej Fink

http://ehcache.org/is very good and light cache. It can be shared between multiple JVMs. Internally it can use JGroups.

http://ehcache.org/是非常好的轻缓存。它可以在多个 JVM 之间共享。在内部,它可以使用 JGroups。