Skip to content

Commit

Permalink
feat(cache): add staleMaxAge option for caching header (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
Intevel authored Apr 19, 2022
1 parent 94fc531 commit 8ff6836
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/runtime/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ export interface CacheEntry<T=any> {
integrity?: string
}

export interface CachifyOptions<T=any> {
name?: string
getKey?: (...args: any[]) => string
transform?: (entry: CacheEntry<T>, ...args: any[]) => any
group?: string
integrity?: any
magAge?: number
swr?: boolean
base?: string
export interface CachifyOptions<T = any> {
name?: string;
getKey?: (...args: any[]) => string;
transform?: (entry: CacheEntry<T>, ...args: any[]) => any;
group?: string;
integrity?: any;
magAge?: number;
swr?: boolean;
staleMaxAge?: number;
base?: string;
}

const defaultCacheOptions = {
Expand Down Expand Up @@ -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}`)
}
Expand Down

0 comments on commit 8ff6836

Please sign in to comment.