Fetch tags with neon db
Answered
Siberian posted this in #help-forum
SiberianOP
Is there any way to have fetch tags with
https://nextjs.org/docs/app/building-your-application/caching#fetch-optionsnexttags-and-revalidatetag
@neondatabase/serverless?https://nextjs.org/docs/app/building-your-application/caching#fetch-optionsnexttags-and-revalidatetag
Answered by riský
you can use [
unstable_cache](https://nextjs.org/docs/app/building-your-application/caching#unstable_cache), but idk if it is the safest (or even what you are asking)45 Replies
like have similar caching such as fetch?
you can use [
unstable_cache](https://nextjs.org/docs/app/building-your-application/caching#unstable_cache), but idk if it is the safest (or even what you are asking)Answer
its just a postgres db, so you can fetch anything as long as it exists on the db. Give further information what you mean by tags etc
@riský you can use [`unstable_cache`](<https://nextjs.org/docs/app/building-your-application/caching#unstable_cache>), but idk if it is the safest (or even what you are asking)
yeah then ^ is basicly the only way for custom fetch implmentations
SiberianOP
but it's unstable :(, what's the best alternative to invalidate the cache?
router.refresh()?that would invalidate client cache
depending on how you use your neondb, you may be able to cache the pages and just revalidate them
SiberianOP
with
revalidatePath?@Siberian with `revalidatePath`?
yeah, you would use this to revalidate pages
and then use router.refresh to make sure the user has it updated
not sure about this ^
@Clown not sure about this ^
i don't believe so
@Clown it can be hard coded
SiberianOP
can you explain this please?
i just wanted to put the docs here: https://nextjs.org/docs/app/building-your-application/caching#fetch-optionsnexttags-and-revalidatetag
revalidatePathvs.router.refresh:
- Callingrouter.refreshwill clear the Router cache, and re-render route segments on the server without invalidating the Data Cache or the Full Route Cache.
- The difference is thatrevalidatePathpurges the Data Cache and Full Route Cache, whereasrouter.refresh()does not change the Data Cache and Full Route Cache, as it is a client-side API.
@Siberian can you explain this please?
im not sure what he is getting at here tbh
@Siberian can you explain this please?
meaning you dont need to fetching the tags from anywhere. you can literally hard-code the tag in the fetch request
cause u initially said something about tags
i guess i just got confused
@Clown meaning you dont need to fetching the tags from anywhere. you can literally hard-code the tag in the fetch request
SiberianOP
yeah, that's what i wanted to do as well but i'm not sure how to do this with neon :D hence my question
how are you fetching your data with neon?
SiberianOP
i wanted to pass a custom fetch function to their basic config but it looks like it doesn't accept any arguments
even if they use the right fetch, you would have to make an insane wrapper to add the tags
@Siberian i wanted to pass a custom fetch function to their basic config but it looks like it doesn't accept any arguments
Technically they provide a databaseurl to you, so you should just be able to use a ORM or something
still the same cache issue
SiberianOP
import { schema } from "...";
import { Pool, neonConfig } from "@neondatabase/serverless";
import { drizzle } from "drizzle-orm/neon-serverless";
import { env } from "@/env.mjs";
neonConfig.fetchConnectionCache = true;
const pool = new Pool({ connectionString: env.DB_URL });
export const db = drizzle(pool, {
schema,
logger: env.NODE_ENV !== "production",
});db.query.someEntry.findMany(...)yeah without using unstable_cache, i don't see how you would use nextjs cache
but using unstable_cache is better than any sketchy implementation of abusing fetch....
SiberianOP
for a production app? you'd think it's better than using
revalidatePath + cache + router.refresh as a temporary solution?its up to you tbh
i would say they are both good implmentations
but you will still need .refresh if the user wants update
and is the "cache" the route cache (not any other one)?
SiberianOP
ahh that cache is only useful for the same request
like if you use the same function twice in a render (only done once)
but it doesn't affect cross requests
SiberianOP
ohhh okay, okay, looks like i misunderstood its functionality
thank you for the advice and for clearing this up :D
@Siberian ohhh okay, okay, looks like i misunderstood its functionality
yeah otherwise unstable_cache is useless
so your question is answered?
SiberianOP
yup :D thank you