alepha@docs:~/docs/reference/primitives$
cat $memoize.md1 min read
#$memoize
#Import
typescript
1import { $memoize } from "alepha";
#Overview
Maximum number of entries to keep in the cache.
- When exceeded, the oldest entry is evicted (FIFO).
- @default 1000 */ max?: number;
/**
- Custom key function. Receives the handler's arguments.
- By default,
JSON.stringify(args)is used. */ key?: (...args: any[]) => string; }
/** 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 |