I have around 7k database entries I want to set into a map. I loop through the data fetched from the db and set it into the map. However, it takes a very long time (around 3 minutes), to set these keys. Is there a better way to do it rather than just looping over the entries and setting them one by one? I'm using a map for cache and run a task every minute for this cache to be updated, but the map itself takes 3 minutes for all the keys to be set.
I'm setting an object as the value, like so:
const data = await fetchDataFromDb();
for (const element of data) cache.set(element.id, element)
cache here is a class extending map (which makes no changes to set method), having some custom methods.