Merlin
Merlin
Explore posts from servers
TTCTheo's Typesafe Cult
Created by Merlin on 9/5/2023 in #questions
weird behavior with unstable_cache
I'm trying to use drizzle with planetscale's database-js inside of an unstable_cache (to leverage the tag caching system).
export async function getArticles() {
return await unstable_cache(
async () => {
return await db.select().from(articles).limit(10);
},
["articles"],
{ revalidate: 3600, tags: ["articles"] }
)();
}
export async function getArticles() {
return await unstable_cache(
async () => {
return await db.select().from(articles).limit(10);
},
["articles"],
{ revalidate: 3600, tags: ["articles"] }
)();
}
pretty simple stuff, but because database-js is based on the fetch api, it breaks when inside of the unstable_cache.
Error: cache: 'force-cache' used on fetch for https://aws.connect.psdb.cloud/psdb.v1alpha1.Database/Execute with 'export const fetchCache = 'only-no-store'
Error: cache: 'force-cache' used on fetch for https://aws.connect.psdb.cloud/psdb.v1alpha1.Database/Execute with 'export const fetchCache = 'only-no-store'
I tried changing the fetch in database-js to use undici's fetch, which fixed the problem, but that doesnt support edge runtime sadly. Anyone any ideas?
1 replies
TTCTheo's Typesafe Cult
Created by Merlin on 3/7/2023 in #questions
refetch useSession data
hi, I have a settings page where I let users change their username. Happens so that that exact username is in the NavBar and needs to be updated. In the navbar I'm using useSession to get the users username. How do I refetch this? I googled around for a bit and running getSession({ triggerEvent: true, broadcast: true }) after mutating the username works to some extend, just not on the same window? It updates the username in other windows though, but not the window where that code is ran.
1 replies