Libraries v5.0.0
    Preparing search index...

    Function cacheResponse

    • Server-side cache response middleware.

      Uses cache-tag definitions from the matched endpoint (already available on ctx.items.__endpoint_meta.cacheTags) to compute deterministic cache keys from request data (params, query, body, headers).

      • GET: Computes cache key → serves cached response if valid → handler never executes. On cache miss, runs the handler and caches the response.
      • Mutation (POST/PUT/PATCH/DELETE): Lets the handler run, then invalidates all cache entries whose tag names start with any of the endpoint's cache tag names. Older in-flight reads cannot refill them.
      • By default, retain at most 1000 keys and bodies up to 65,536 bytes. Private/no-store and Set-Cookie responses are not cached. Install after authorization and encode every identity/tenant/representation dimension in tag properties.

      Parameters

      Returns Middleware

      A server-side Middleware.

      server.handle(ListTodos, listHandler, {
      middlewares: [cacheResponse({ defaultTtl: 30_000 })]
      });