Getting 304 Not Modified for page and getting always stale data
Unanswered
Basset Fauve de Bretagne posted this in #help-forum
Basset Fauve de BretagneOP
I'm using
Thanks in advance!
unstable_cache to revalidate some operations/external calls for X hours. When I deployed for the first time everything was correct, even after the first revalidation. After that, I started seeing that the page was always containing the stale data and via network I see the response status 304 (not modified) for that page. Anyone knows what's going on? If I redeploy it will start working. Thanks in advance!
4 Replies
Basset Fauve de BretagneOP
@Southern rough shrimp 🙠, basically this:
"use server";
import { unstable_cache as cache } from "next/cache";
import { parseCompaniesData } from "../parser";
export const getParsedCompaniesData = cache(
async () => {
const data = await parseCompaniesData();
const updatedAtISODate = new Date().toISOString();
return {
companies: data.companies,
availableLocations: data.availableLocations,
availableCategories: data.availableCategories,
updatedAtISODate,
};
},
["companies"],
{
revalidate: 21600, // 6 hours
},
);
export const getParsedCompanyBySlug = async (slug: string) => {
const { companies } = await getParsedCompaniesData();
return companies.find((company) => company.slug === slug);
};and then i'm using this in a root page /:
export default async function CompaniesPage() {
const {
availableCategories,
availableLocations,
companies,
updatedAtISODate,
} = await getParsedCompaniesData();
return (
<CompaniesClientPage
companies={companies}
availableCategories={availableCategories}
availableLocations={availableLocations}
updatedAtISODate={updatedAtISODate}
/>
);
}