#chache

3 messages · Page 1 of 1 (latest)

limber warren
#

should db.get calls be replaced by query for better caching??

tulip meteorBOT
#

Hi @limber warren. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Convex already caches at the query function level, not at the individual db.get call level.

  • db.get is just a low-level read you use inside a query or mutation. It doesn’t have its own separate cache; it’s fast and intended to be used freely (including N+1 style patterns). [One-to-many]
  • Query functions (query({ ... })) are what Convex automatically caches and keeps reactive. If you call the same query with the same args, Convex returns a cached result and only recomputes when underlying documents change. [Queries caching; Realtime]

So:

  • You should not “replace db.get with query” for caching.
  • Instead, structure your reads so that all app reads go through query functions, and inside those queries you can use db.get, db.query, etc. as needed. [Zen of Convex; Reading data]

If you’re already using queries for reads, you’re already getting Convex’s caching; changing db.get calls to something else won’t improve caching.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: