Hi, I have a list of about 50 objects that come from a database that need to be looked up and referenced A LOT. I had originally created a function like this and wrapped it in the unstable cache to minimize database traffic.
export const getShowMapByUrl = unstable_cache(async (): Promise<string> =>
{
console.log("getShowMapByUrl called (cached)");
const client = await clientPromise;
const db = client.db(MAINDB);
const collection = db.collection(SHOW_COLL);
const showsMap = new Map<string, ShowType>();
const cursor = collection.find({},{projection:{}});
await cursor.forEach((show: ShowType) => {
if (show.internalUrl) {
showsMap.set(show.internalUrl.toLowerCase(), show);
}
})
return JSON.stringify(Array.from(showsMap.entries()));;
},[],{revalidate:false,tags:["showlist"]});
Now, I am seeing that my usage data is blowing up with Data Cache Reads, which I assume (but can't confirm) is related to this. Given that this data is pretty static, is there a better more efficient and cost-effective way to do this?
I was thinking of creating a static /api/getShowMapByUrl page that would get built during build time. But I think that would also be cached and cost against Data Cache Reads, is that correct?
Open to any ideas! Thanks.