How to add tags on db call on server component to revalidate using tags ?
Answered
Tan posted this in #help-forum
TanOP
I wanted to revalidate db fetch using tags. It is being done with path but I couldn't figure out how can I revalidate using tags since I am not using fetch.
Here is my code snippet :
Here is my code snippet :
const page = async () => {
await connect();
const posts = await Post.find();
return (
<div>
<div className="container mx-auto py-8">
<h1 className="text-2xl font-semibold text-center mb-4">
Create a New Post
</h1>
<Form />
</div>
<div className="max-w-4xl mx-auto">
<h1 className="text-3xl"></h1>
{posts.map((post) => (
<li>{post.title}</li>
))}
</div>
</div>
);
};Answered by fuma
Unfortunately, for now, you can't cache or revalidate database calls. Instead, you can revalidate the whole page with
Next.js also provides a
revalidatePath.Next.js also provides a
unstable_cache, but it is discouraged to use in production and might not work as expected.2 Replies
@Tan I wanted to revalidate db fetch using tags. It is being done with path but I couldn't figure out how can I revalidate using tags since I am not using fetch.
Here is my code snippet :
js
const page = async () => {
await connect();
const posts = await Post.find();
return (
<div>
<div className="container mx-auto py-8">
<h1 className="text-2xl font-semibold text-center mb-4">
Create a New Post
</h1>
<Form />
</div>
<div className="max-w-4xl mx-auto">
<h1 className="text-3xl"></h1>
{posts.map((post) => (
<li>{post.title}</li>
))}
</div>
</div>
);
};
Unfortunately, for now, you can't cache or revalidate database calls. Instead, you can revalidate the whole page with
Next.js also provides a
revalidatePath.Next.js also provides a
unstable_cache, but it is discouraged to use in production and might not work as expected.Answer
@fuma Unfortunately, for now, you can't cache or revalidate database calls. Instead, you can revalidate the whole page with `revalidatePath`.
Next.js also provides a `unstable_cache`, but it is discouraged to use in production and might not work as expected.
TanOP
Thank you. I could use revalidate path but wondered if there are features that I have missed.
Apreaciate your time 😃
Apreaciate your time 😃