Skip to content

Question: is it worth to store the reference to a map? #1006

Open
@dgonzalezKentech

Description

@dgonzalezKentech

Go version: 1.22.4
Hazelcast Go Client version: v1.4.2

Simple question:

we use HZ to store token information with some maps, not too many (5),

We do like 1000 req/s to 3 or 4 maps, but for every single request to the map.get we get the map first. (GetMap)

We could store the map reference in a "golang map" (as we have a generic interface with HZ) in our code instead of relaying on the HZ function to get the map.

Would this be worth it? Is the GetMap doing a request to the server every single time? I checked the code of the library and seems to save some references internally...

`

   func (repo CacheRepo) Get(ctx context.Context, key, mapName string) (data interface{}, err error) {
logger.LOGContext(ctx).Debugf("[CacheRepo][Get][key:%s][mapName:%s]", key, mapName)

defer func(start time.Time) {
	if err == nil {
		tools.EndCacheResponseTimer(start, "get")
	}
}(time.Now())

cacheMap, err := repo.Cache.GetMap(ctx, mapName)
if err != nil {
	return nil, fmt.Errorf("[CacheRepo][Get][GetMap][mapName:%s][err:%w]", mapName, err)
}
data, err = cacheMap.Get(ctx, key)
if err != nil {
	return nil, fmt.Errorf("[CacheRepo][Get][cacheMap.Get][mapName:%s][key:%s][err:%w]", mapName, key, err)
}

logger.LOGContext(ctx).Debugf("[CacheRepo][Get][data:%v]", data)
return data, nil
   }

`

like somethink like (pseudo code):

map, ok := mymaps[mapName] if !ok { map = repo.Cache.GetMap(ctx, mapName) mymaps[mapName] = map }

Thank you

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions