alepha@docs:~/docs/reference/primitives$
cat $memoize.md | pretty1 min read
#$memoize
#Import
typescript
1import { $memoize } from "alepha";
#Overview
Lightweight in-process memoization middleware.
Caches handler results in a plain Map — no external store, no serialization,
no provider dependency. Process-local only. Entries live until eviction by capacity.
typescript
1class Api {2 getStats = $action({3 use: [$memoize({ max: 100 })],4 handler: async () => this.repo.aggregate(),5 });6}
For more advanced caching, use
$cachefrom "alepha/cache" instead — it supports TTL, invalidation, external stores (Redis).
#Options
| Option | Type | Required | Description |
|---|---|---|---|
max |
number |
No | Maximum number of entries to keep in the cache |
key |
Object |
No | Custom key function |