TripleSpeederT
Convex Community3y ago
18 replies
TripleSpeeder

best practices/examples to use httpClient with unstable_cache

For some rather static parts of my app i want to use next.js server-side rendering, making use of the data cache to reduce the number of queries hitting convex layer. So I'm using the ConvexHttpClient and wrap it in unstable_cache from next/cache.
A working example:
const getCachedBikeModel = unstable_cache(
  async (bikeModelId: Id<"bikeModel">) => {
    return client.query(api.bikeModel.getFullBikeModelQuery, {
      bikeModelId,
    });
  },
  ["getFullBikeModel"],
  {
    revalidate: 60, // 1 minute
  },
);

In the component i can then use it with const bikeModel = await getCachedBikeModel(bikeModelId)

This works as expected, but it's a lot of boilerplate to manually create wrappers. Is there any example/guide how I can automatically generate these from the api?
Was this page helpful?