UNPKG

nuxt-multi-cache

Version:

SSR route, component and data cache for Nuxt.js

23 lines (22 loc) 644 B
import { defineEventHandler, readBody, createError } from "h3"; import { checkAuth, getCacheInstance } from "./helpers/index.js"; async function getKeysToPurge(event) { const body = await readBody(event); if (body && Array.isArray(body)) { return body; } throw createError({ statusCode: 400, statusMessage: "No valid keys provided." }); } export default defineEventHandler(async (event) => { await checkAuth(event); const affectedKeys = await getKeysToPurge(event); const cache = getCacheInstance(event); affectedKeys.forEach((key) => cache.removeItem(key)); return { status: "OK", affectedKeys }; });