From 40f26b3eebbcac27f945d9f45392c4885fd5a265 Mon Sep 17 00:00:00 2001 From: Conner Date: Fri, 15 Apr 2022 20:42:12 +0200 Subject: [PATCH 1/3] Delete :name.ts --- examples/api-routes/api/hello/:name.ts | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 examples/api-routes/api/hello/:name.ts diff --git a/examples/api-routes/api/hello/:name.ts b/examples/api-routes/api/hello/:name.ts deleted file mode 100644 index d016ff819f..0000000000 --- a/examples/api-routes/api/hello/:name.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { defineEventHandler } from 'h3' - -export default defineEventHandler(event => `Hello ${event.context.params.name}!`) From c07da5b5bc4047cebbed5c245fb41d754f898074 Mon Sep 17 00:00:00 2001 From: Conner Bachmann <59223342+Intevel@users.noreply.github.com> Date: Fri, 15 Apr 2022 21:01:12 +0200 Subject: [PATCH 2/3] feat(cache): add options for swr max-age --- src/runtime/cache.ts | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/runtime/cache.ts b/src/runtime/cache.ts index 784ef338c5..b2c8a82494 100644 --- a/src/runtime/cache.ts +++ b/src/runtime/cache.ts @@ -10,15 +10,16 @@ export interface CacheEntry { integrity?: string } -export interface CachifyOptions { - name?: string - getKey?: (...args: any[]) => string - transform?: (entry: CacheEntry, ...args: any[]) => any - group?: string - integrity?: any - magAge?: number - swr?: boolean - base?: string +export interface CachifyOptions { + name?: string; + getKey?: (...args: any[]) => string; + transform?: (entry: CacheEntry, ...args: any[]) => any; + group?: string; + integrity?: any; + magAge?: number; + swr?: boolean; + staleMaxAge?: number; + base?: string; } const defaultCacheOptions = { @@ -135,7 +136,11 @@ export function defineCachedEventHandler (handler: CompatibilityEventHandler, op if (opts.magAge) { cacheControl.push(`s-maxage=${opts.magAge}`) } - cacheControl.push('stale-while-revalidate') + if (opts.staleMaxAge) { + cacheControl.push(`stale-while-revalidate=${opts.staleMaxAge}`) + } else { + cacheControl.push('stale-while-revalidate') + } } else if (opts.magAge) { cacheControl.push(`max-age=${opts.magAge}`) } From 225759cfc348e33b8021676e684deff523a985a3 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Tue, 19 Apr 2022 12:54:59 +0200 Subject: [PATCH 3/3] fix lint issue --- src/runtime/cache.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/runtime/cache.ts b/src/runtime/cache.ts index b2c8a82494..12607b3eec 100644 --- a/src/runtime/cache.ts +++ b/src/runtime/cache.ts @@ -136,11 +136,11 @@ export function defineCachedEventHandler (handler: CompatibilityEventHandler, op if (opts.magAge) { cacheControl.push(`s-maxage=${opts.magAge}`) } - if (opts.staleMaxAge) { - cacheControl.push(`stale-while-revalidate=${opts.staleMaxAge}`) - } else { - cacheControl.push('stale-while-revalidate') - } + if (opts.staleMaxAge) { + cacheControl.push(`stale-while-revalidate=${opts.staleMaxAge}`) + } else { + cacheControl.push('stale-while-revalidate') + } } else if (opts.magAge) { cacheControl.push(`max-age=${opts.magAge}`) }