Skip to Content
DocumentationGuidesNelios Cache

Nelios Cache

Nelios Cache in combination with Next.js revalidation automatically revalidates cache for content types.


Setup

Create a file at your frontend at src/app/api/revalidate/route.ts

import { NextRequest, NextResponse } from 'next/server'; import { revalidatePath, revalidateTag } from 'next/cache'; import { revalidateRequest } from '@repo/lib/revalidate'; import i18nConfig from '@/i18nConfig'; export async function POST(req: NextRequest) { return await revalidateRequest(req as never, i18nConfig); //or revalidateRequest16 depending on the nextjs version if your project }

At your .env ( or environment variables in vercel ) add the secret

REVALIDATE_SECRET_TOKEN=XXXXXXXXXXXXXXXXX

The token can be found at the backend .env or at the frontend variables of any other site that uses it.

In the .env of the backend add FRONT_END_URL_<SITENAME>

Usage

In order for the automatic revalidation to work, you need to add the proper tags for each request. The tag must be the singular name of the content type and the only exception is the homepage single type that it’s tag is ‘home’

Example requests:

const [postCategories, posts, events, eventsList, hotels, restaurants, rooms] = await Promise.all([ RestAPI('/api/andronis-posts-categories', catQueryParams, false, ['post', 'category']), RestAPI('/api/andronis-posts', postQueryParams, false, ['post']), RestAPI('/api/andronis-events', eventQueryParams, false, ['event']), RestAPI('/api/andronis-events-categories', eventsListQueryParams, false, ['events', 'eventcategory']), RestAPI('/api/andronis-pages', hotelsParams, false, ['page']), RestAPI('/api/andronis-restaurants', restaurantQueryParams, false, ['restaurant']), RestAPI('/api/andronis-rooms', roomQueryParams, false, ['room']), ]);
Last updated on