Next.js Discord

Discord Forum

How to clear cache on server side functions?

Answered
North Pacific hake posted this in #help-forum
Open in Discord
North Pacific hakeOP
Hi there, I am using a server side functions to register however, it ends up caching the response from the server. This is happening the point where if the user is already registered with the same email it will respond with the same message that is used to let them know that they received a confirmation email. How do I make a server side action not have cache?

Server-side function:
"use server";

import { pb } from "../../lib/pb";

export const registerUser = async (data) => {
  console.log(data);
  try {
    const result = await pb.collection("users").create(data);
    console.log(result);
    console.log(`created user: ${data.email}`);
    return { success: true, message: "Please check your email." };
...


Client side:
  const handleSubmit = async (e) => {
    e.preventDefault();
    const data = {
      email,
      password,
      passwordConfirm,
    };
    const response = await registerUser(data);
    if (response.success) {
      toast.success(`${response.message}`);
    } else {
      toast.error(`${response.message}`);
    }
  };
Answered by Ray
I think server action shouldn't be cached
try this
await pb.collection("users").create(data,{cache: 'no-store'});
View full answer

5 Replies

Answer
@Ray I think server action shouldn't be cached try this ts await pb.collection("users").create(data,{cache: 'no-store'});
North Pacific hakeOP
You're the man Ray, exactly what I needed on the dot once again 💪🏻
@Ray I think server action shouldn't be cached try this ts await pb.collection("users").create(data,{cache: 'no-store'});
North Pacific hakeOP
It's weird cause also deleting the .next folder also fixed it temporarily
@North Pacific hake It's weird cause also deleting the .next folder also fixed it temporarily
because the data cache is store inside the .next folder
North Pacific hakeOP
i see