TripleSpeederT
Convex Communityโ€ข3y agoโ€ข
10 replies
TripleSpeeder

Caching behaviour of HttpClient

I'm seriously confused now, trying to understand how/why convex HttpClient is caching responses.
I have this convex query:
export const getUserByUsername = query({
  args: {
    username: v.string(),
  },
  handler: async (ctx, { username }) => {
    console.log(`getUserByUsername ${username}...`);
    const result = await ctx.db
      .query("users")
      .withIndex("by_clerk_username", (q) =>
        q.eq("clerkUser.username", username),
      )
      .unique();
    console.log(
      `getUserByUsername ${username} result description:`,
      result?.description,
    );
    return result;
  },
});

The query is logging the description field of the username.

Now I modify the description field by a mutation. But when rendering the profile page for that user ( using ConvexHTTPclient, not the
useQuery
hook), I still get the old value. Initially I thought that this is an issue with next.js caching, but after drilling through all layers I think the problem is on convex side?

My next dev terminal logs the following console output:
[CONVEX Q(users:getUserByUsername)] [LOG] 'getUserByUsername mike...'
[CONVEX Q(users:getUserByUsername)] [LOG] 'getUserByUsername mike result description:' 'bbbbbbb'

But i have changed the description to 'XXXXXXX' before!
When I run the same query through npx convex run i get the expected result 'XXXXXXX'

My understanding is that by seeing the CONVEX Q... log in my terminal that indeed the convex DB is hit, so any internal caches of next.js are not involved anymore. But looking at the convex dashboard logs, there is no according log entry created, so where is the output in my terminal coming from? It seems for me that the convex-internal DB cache is not invalidated by my mutation that updates the users table. But why do i get the correct result through npx convex run then?

Pls halp ๐Ÿ™‚
Was this page helpful?