libsql-client-ts
libsql-client-ts copied to clipboard
Caching issue with Next.js and Turso dev server
Discovered a strange behavior inside a Next.js application together with Turso dev server (using http url).
Issue: New entries where not returned from a query.
After a lot of digging, I discovered a directory named fetch-cache and saw that there are the requests to Turso cached. Deleting this directory solved the issue temporarily as the new records where returned from the query thereafter.
To fix the problem, a parameter { cache: 'no-store' } should be included with the fetch call. (More info in the Next.js documentation here)
I could fix this locally by adding a custom fetch function to my config:
function noCacheFetch(
input: string | URL | globalThis.Request,
init?: RequestInit,
): Promise<Response> {
return fetch(input, { ...init, cache: 'no-store' });
}
const client = createClient({
...,
fetch: noCacheFetch
});
But I feel it would be better to include this in the library as default to avoid this problem to future users. What do you think?