集群共享缓存

发布于 2024-07-23 06:41:39 字数 1539 浏览 3 评论 0原文

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

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

发布评论

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

评论(8

梦开始←不甜 2024-07-30 06:41:40

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

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

追我者格杀勿论 2024-07-30 06:41:40

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

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

-柠檬树下少年和吉他 2024-07-30 06:41:39

这个怎么样?

有一个本地 ConcurrentHashMap 作为本地缓存。
创建 Hazelcast 分布式地图/缓存。
开始监听分布式映射事件并更新本地 ConcurrentHashMap。

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

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

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.

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());            
        }
}
空心空情空意 2024-07-30 06:41:39

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

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

Cache cache = manager.getCache();

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

--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

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

Cache cache = manager.getCache();

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

--Hardy

无敌元气妹 2024-07-30 06:41:39

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

感谢您的回答。

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 :)

Thanks for your answers.

笑脸一如从前 2024-07-30 06:41:39

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

不久前有一个关于缓存领域的 JSR,执行以下任一操作即可满足要求: http://java-source.net/open-source/cache-solutions/jcache

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

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

Have you considered Terracotta? Might be overkill: 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 ?

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

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...

软的没边 2024-07-30 06:41:39

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

编辑:哦,JBossCache是​​独立于JBoss应用服务器的,你可以在任何环境中使用它。 如果说有什么不同的话,那就是它在 JBossAS 之外比在 JBossAS 内部运行得更好。

I've used a few technologies in this area, I can highly recommend JBoss Cache as 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.

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.

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