#hey anybody know how can i achieve stale

1 messages · Page 1 of 1 (latest)

viscid bay
#
export const getServerSideProps = pageHandler(async (context) => {
    const tokenLocator = getRequiredParam(context.query, "tokenLocator");
    const token = await TokenFactory.getFromLocator(tokenLocator);
    const tokenProjection = await token.projectToClient();

    if (tokenProjection.metadata != null) {
        // Because the cache has a maxage of 1s, the next request will always cause the cache to be refreshed in the background
        // While the cache is being refreshed, the stale cache will be served to the user from memory
        // If no requests are made within 1 day, the cache will be cleared
        context.res.setHeader("Cache-Control", "public, s-maxage=1, max-age=1, stale-while-revalidate=86400");
    }

    return {
        props: {
            token: serializeToJSON(tokenProjection),
        },
    };
});
short sundialBOT
#

Hi @viscid bay. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Sorry @viscid bay, I seem to be having a bit of trouble. Don't worry though, I've pinged my supprt and they will try to fix me up! :technologist:

Perhaps try again in 15mins?

viscid bay
#

this was my pages dir code

viscid bay
#

hmm i guess this is actually replicated by export const revalidate = 1;