Next.js Discord

Discord Forum

caching

Unanswered
Sage Thrasher posted this in #help-forum
Open in Discord
Sage ThrasherOP
'use server';

import { auth } from "@/auth/auth";
import type { SafeError } from "@/typing";

export async function refreshUser(): Promise<SafeError | void> {
    const session = await auth();
    if (!session) return { error: 'Something went wrong' };

    const response = await fetch(`${process.env.API_ENDPOINT}/users/${session.user.id}/update`, {
        headers: {
            'Authorization': process.env.API_AUTHORIZATION
        },
        next: {
            revalidate: 120
        },
    });

    if (!response.ok) {
        return { error: 'Something went wrong' };
    }

    const data = await response.json();
    console.log(data)
}


'data' returns a new Date() and im watching the api logs, and the next revalidate doesn't work at all, everytime i call this server action, this fetch request is made and im not sure why it's not caching

1 Reply

Sage ThrasherOP
if i open the console and call the function, the fetch isnt cached and is made on each call
if i close the console and refresh the page, the cache works as expected