-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexecutionMemoization.model.ts
More file actions
38 lines (30 loc) · 1.11 KB
/
executionMemoization.model.ts
File metadata and controls
38 lines (30 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { FunctionMetadata } from './executionFunction.model';
export const memoizationKey = Symbol('execution-engine/memoize');
/** Default expiration that ensures multiple rapid calls can reuse the stored result */
export const memoizationDefaultExpirationMs = 100;
/** Maximum allowable expiration time Prevent excessive retention */
export const memoizationMaxExpirationMs = 1000;
/**
* Represents the context of a memoized function execution.
*/
export interface MemoizationContext <O> {
metadata: FunctionMetadata;
inputsHash: string;
isMemoized: boolean;
value?: Promise<O> | O;
}
/**
* A handler function that processes the memoization context.
*/
export type MemoizationHandler<O> = (info: MemoizationContext<O>) => void;
export interface MemoizeOptions<O> {
/** Unique identifier for the function being memoized */
functionId: string;
/**
* Optional expiration time in milliseconds for the cached result.
* Default is 100ms, capped at 1000ms to prevent excessive retention.
*/
expirationMs?: number;
/** Custom handler for memoization logic */
memoizationHandler?: MemoizationHandler<O>;
}