要存储在 hazelcast 中用于缓存的 IMap 中的数据存储在 hazelcast 服务器中或 hazelcast 实例所在的位置 运行?

Data to be stored in IMap in hazelcast for caching is stored in hazelcast server or where hazelcast instance is running?

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

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.

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