Skip to content

Commit

Permalink
docs(jsdoc): Cache Middleware (#2692)
Browse files Browse the repository at this point in the history
  • Loading branch information
goisaki authored and yusukebe committed May 24, 2024
1 parent c906135 commit 8ae8f9e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
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

0 comments on commit 8ae8f9e

Please sign in to comment.