Response Helpers

revalidate

Edit this page

Revalidate will receive the either a cache key or an array of cache keys and invalidate those queries.

The code below will revalidate the getTodo query with the cache key.

"/actions/update-todo.ts"{4}
import { action, revalidate } from "@solidjs/router";
const updateTodo = action(async (todo: Todo) => {
await putTodo(todo.id, todo);
return revalidate(getTodo.keyFor());
});

To better understand how queries work, check the query documentation.


Force Revalidation

The revalidate function also accepts a second parameter to force the revalidation of the cache data.

"/actions/update-todo.ts"{4}
import { action, revalidate } from "@solidjs/router";
const updateTodo = action(async (todo: Todo) => {
await putTodo(todo.id, todo);
return revalidate(getTodo.keyFor(), true);
});

TypeScript Signature

function revalidate(key?: string | string[] | void, force?: boolean): Promise<void>;
Report an issue with this page