Cache Middleware #

The Cache middleware uses the Web Standard’s Cache API. It caches a given response according to the Cache-Control headers.

The Cache middleware currently supports Cloudflare Workers projects using custom domains and Deno projects using Deno 1.26+, but doesn’t supports Lagon. See Usage below for instructions on each platform.

Import #

import { Hono } from 'hono'
import { cache } from 'hono/cache'
import { Hono } from ''
import { cache } from ''

Usage #

app.get('*', cache({ cacheName: 'my-app', cacheControl: 'max-age=3600' }))
// Must use `wait: true` for the Deno runtime
app.get('*', cache({ cacheName: 'my-app', cacheControl: 'max-age=3600', wait: true }))

Options #

  • cacheName: string - required
    • The name of the cache. Can be used to store multiple caches with different identifiers.
  • wait: boolean
    • 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. Default is false.
  • cacheControl: string
    • A string of directives for the Cache-Control header. See the MDN docs for more information. When this option is not provided, no Cache-Control header is added to requests.
© Hono developers.
Built with Hugo & Hugo Book Theme - Not Hono :)