Skip to content

How to clear the whole cache #717

Discussion options

You must be logged in to vote

Hey @aryan-mehrabi! Currently, there's no direct way to clear the entire cache (cache from all Handlers simultaneously) from the Next.js API. However, you can implement a workaround. You can create an API route in your Next.js app, establish a direct connection to your cache stores, and clear them from there. Please use this approach carefully; do not expose this API to the public.

Example for the Redis:

import { createClient, RedisFlushModes } from 'redis';

export const dynamic = 'force-dynamic';

export async function GET(): Promise<Response> {
    const client = createClient({
        url: process.env.REDIS_URL,
    });

    await client.connect();

    // Use one of the following met…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@aryan-mehrabi
Comment options

@better-salmon
Comment options

Answer selected by aryan-mehrabi
Comment options

You must be logged in to vote
1 reply
@aryan-mehrabi
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #716 on August 26, 2024 16:15.