gpt4 book ai didi

java - 要存储在 hazelcast 中用于缓存的 IMap 中的数据存储在 hazelcast 服务器中还是存储在 hazelcast 实例运行的位置?

转载 作者:行者123 更新时间:2023-12-01 09:09:31 26 4
gpt4 key购买 nike

我已经编写了用于缓存的 hazelcast 缓存框架,并通过构造函数注入(inject)专门编写了一个用于缓存的 hazelcast 服务器。只是想知道 IMap 对象存储在哪里?它是在我的 hazelcast 服务器中还是在运行此类的应用程序中?

public String hazelClientServer;
public static HazelcastInstance hazelcastInstance;

// setting through constructor injection
public HazelCastCache(String hazelClientServer) {
this.hazelClientServer = hazelClientServer;
}



private IMap<Object, Object> getMap(String mapName,String configName){

Config conf = new Config(configName);

MapConfig mapConfig = new MapConfig(mapName);
mapConfig.setEvictionPolicy(EvictionPolicy.LRU);
mapConfig.setEvictionPercentage(10);
conf.addMapConfig(mapConfig);
conf.getNetworkConfig().setPublicAddress(hazelClientServer);
hazelcastInstance = Hazelcast.getOrCreateHazelcastInstance(conf);
IMap<Object, Object> hazelMap=hazelcastInstance.getMap(mapName);
return hazelMap;
}

public Object getDataFromCache(String mapName,String configName,Object key){

IMap<Object, Object> dataMap = getMap(mapName,configName);
Object data = dataMap.get(key);
return data;

}

public void addDataToCache(String mapName,String configName,Object key,Object value){

IMap<Object, Object> dataMap = getMap(mapName,configName);
dataMap.put(key, value);

}

最佳答案

这取决于您启动集群的方式。

这是文档中的内容:

In the embedded topology, members include both the data and application. This type of topology is the most useful if your application focuses on high performance computing and many task executions. Since application is close to data, this topology supports data locality.

In the client-server topology, you create a cluster of members and scale the cluster independently. Your applications are hosted on the clients, and the clients communicate with the members in the cluster to reach data.

通过查看您的代码,您将以嵌入式模式启动集群/节点,在这种情况下,数据驻留在您的应用程序服务器本身。因此,您还需要考虑缓存大小,以便为应用程序容器分配内存。

关于java - 要存储在 hazelcast 中用于缓存的 IMap 中的数据存储在 hazelcast 服务器中还是存储在 hazelcast 实例运行的位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41011763/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com