alepha@docs:~/docs/reference/primitives$
cat $etag.md | pretty
1 min read

#$etag

#Import

typescript
1import { $etag } from "alepha/server/etag";

#Overview

Middleware that enables ETag-based response caching per-route.

Sets per-request etag options in the ALS context. The global ServerEtagProvider hooks read these to generate ETags, handle 304s, and optionally store responses.

When store is enabled, the middleware also checks the cache before calling the handler, short-circuiting on cache hits.

Route middleware — works inside $action, $page, or any pipeline.

typescript
 1class UserController { 2  // ETag only (no response caching) 3  getUser = $action({ 4    use: [$etag()], 5    handler: async ({ params }) => { ... }, 6  }); 7  8  // ETag + response caching (store) 9  getProfile = $action({10    use: [$etag(true)],11    handler: async ({ params }) => { ... },12  });13 14  // Fine-grained control15  getStats = $action({16    use: [$etag({ store: { ttl: [5, "minutes"] }, control: { public: true, maxAge: 300 } })],17    handler: async ({ params }) => { ... },18  });19}

#Options

Option Type Required Description
store true | DurationLike | CachePrimitiveOptions No If true, enables storing cached responses
etag true No If true, enables ETag support for the cached responses.