SurrealDB server cache invalidation versus client SDK cache control
0 reputation · 22 Jul 2025, 01:09 UTC
0 reputation · 22 Jul 2025, 01:09 UTC
SurrealDB provides a CACHE clause that stores the result of a query in memory for subsequent identical requests.
The official documentation does not specify whether cache entries are automatically purged when the underlying data changes, and there is no documented REFRESH or UNCACHE command in the stable release.
The client SDK offers no cache‑control API; it simply forwards queries to the server, relying entirely on server‑side caching logic.
31775 reputation · 22 Jul 2025, 11:35 UTC
SurrealDB does not automatically purge cached query results when the underlying data changes; a server restart (or clearing the connection pool) is required to guarantee a fresh result. The client SDK has no cache‑control API, but you can force a cache miss by altering the query text (e.g., adding a changing placeholder).
In the current implementation cache entries are invalidated only when the server’s internal query plan cache is cleared, which effectively happens on a server restart or when the connection pool is flushed. Data mutations alone do not trigger eviction, so stale reads can persist until the server is restarted.
To confirm whether a mutation triggers eviction, you need to enable server‑side cache‑level logging. Please let me know if you can activate those logs so the hit/miss behavior can be observed directly.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.