Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(jsdoc): Cache Middleware #2692

Merged
merged 1 commit into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions deno_dist/middleware/cache/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
import type { Context } from '../../context.ts'
import type { MiddlewareHandler } from '../../types.ts'

/**
* cache middleware for Hono.
*
* @see {@link https://hono.dev/middleware/builtin/cache}
*
* @param {Object} options - The options for the cache middleware.
* @param {string | Function} options.cacheName - The name of the cache. Can be used to store multiple caches with different identifiers.
* @param {boolean} [options.wait=false] - A boolean indicating if Hono should wait for the Promise of the `cache.put` function to resolve before continuing with the request. Required to be true for the Deno environment.
* @param {string} [options.cacheControl] - A string of directives for the `Cache-Control` header.
* @param {string | string[]} [options.vary] - Sets the `Vary` header in the response. If the original response header already contains a `Vary` header, the values are merged, removing any duplicates.
* @param {Function} [options.keyGenerator] - Generates keys for every request in the `cacheName` store. This can be used to cache data based on request parameters or context parameters.
* @returns {MiddlewareHandler} The middleware handler function.
* @throws {Error} If the `vary` option includes "*".
*
* @example
* ```ts
* app.get(
* '*',
* cache({
* cacheName: 'my-app',
* cacheControl: 'max-age=3600',
* })
* )
* ```
*/
export const cache = (options: {
cacheName: string | ((c: Context) => Promise<string> | string)
wait?: boolean
Expand Down
25 changes: 25 additions & 0 deletions src/middleware/cache/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
import type { Context } from '../../context'
import type { MiddlewareHandler } from '../../types'

/**
* cache middleware for Hono.
*
* @see {@link https://hono.dev/middleware/builtin/cache}
*
* @param {Object} options - The options for the cache middleware.
* @param {string | Function} options.cacheName - The name of the cache. Can be used to store multiple caches with different identifiers.
* @param {boolean} [options.wait=false] - A boolean indicating if Hono should wait for the Promise of the `cache.put` function to resolve before continuing with the request. Required to be true for the Deno environment.
* @param {string} [options.cacheControl] - A string of directives for the `Cache-Control` header.
* @param {string | string[]} [options.vary] - Sets the `Vary` header in the response. If the original response header already contains a `Vary` header, the values are merged, removing any duplicates.
* @param {Function} [options.keyGenerator] - Generates keys for every request in the `cacheName` store. This can be used to cache data based on request parameters or context parameters.
* @returns {MiddlewareHandler} The middleware handler function.
* @throws {Error} If the `vary` option includes "*".
*
* @example
* ```ts
* app.get(
* '*',
* cache({
* cacheName: 'my-app',
* cacheControl: 'max-age=3600',
* })
* )
* ```
*/
export const cache = (options: {
cacheName: string | ((c: Context) => Promise<string> | string)
wait?: boolean
Expand Down