Skip to content
This repository has been archived by the owner on Jun 27, 2024. It is now read-only.

Commit

Permalink
refactor(core): deprecate cache.duration option (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
boywithkeyboard authored Jun 10, 2023
1 parent f1d7324 commit 00f1bdb
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions cheetah.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,15 @@ export type Config<
*/
name: string
/**
* Duration in seconds for how long a cached response should be held in memory.
* Duration in seconds for how long a response should be cached.
*
* @deprecated Use `maxAge` instead. This option will be removed in the near future.
*/
duration: number
duration?: number
/**
* Duration in seconds for how long a response should be cached.
*/
maxAge?: number
}

/**
Expand Down Expand Up @@ -83,7 +89,10 @@ export class cheetah<

this.#base = config.base === '/' ? undefined : config.base
this.#cors = config.cors
this.#cache = config.cache
this.#cache = config.cache ? {
name: config.cache.name,
maxAge: config.cache.maxAge ?? config.cache.duration ?? 0
} : undefined
this.#debugging = config.debug ?? false
this.#validator = config.validator
this.#error = config.error
Expand Down Expand Up @@ -422,9 +431,9 @@ export class cheetah<
'access-control-allow-origin': this.#cors
}),
...(request.method === 'GET' && {
'cache-control': !this.#cache || this.#cache.duration === 0
'cache-control': !this.#cache || this.#cache.maxAge === 0
? 'max-age=0, private, must-revalidate'
: `max-age: ${this.#cache.duration}`
: `max-age: ${this.#cache.maxAge}`
})
}

Expand Down

0 comments on commit 00f1bdb

Please sign in to comment.