UNPKG

baked-recipe-admin

Version:

Baked is an opinionated framework for .NET in backend and Nuxt in frontend. This is a recipe package that brings together all the components one needs for an Admin UI.

26 lines (22 loc) 774 B
import { defineNuxtPlugin, useRuntimeConfig } from "#app"; import { useCache } from "#imports"; export default defineNuxtPlugin({ name: "cache-application", enforce: "pre", setup(nuxtApp) { const { public: { cacheApplication } } = useRuntimeConfig(); const cache = useCache("cache:application", cacheApplication.expirationInMinutes); const { $fetchInterceptors } = nuxtApp; $fetchInterceptors.register( "cache-application", async({ request, options }, next) => { if(options.attributes["client-cache"] !== "application") { return await next(); } return await cache.getOrCreate(cache.buildKey(request, options.query), next); }, // should run before other interceptors -10 ); } });