$memoize
$memoize(function?) -> function<f-:f>If function is omitted, the current context value is used.
Source: FUME
Availability
Community v3.2.0+
Enterprise v3.2.0+
Documentation
$memoize() wraps a function and returns another function that caches results for the lifetime of the current evaluation.
- Repeated calls with the same arguments during one evaluation reuse the cached result.
- If the wrapped function is still running, repeated calls with the same arguments wait for that same result instead of starting the work again.
- Successful results stay cached for the rest of the evaluation.
The cache key is based on the argument values you pass in. Arrays and objects are supported, but if any argument is a function, the memoized call throws an error instead of trying to cache it.
The cache is per evaluation. A fresh evaluation starts with a fresh memoized wrapper state.
Examples
Reuse repeated practitioner lookups inside one evaluation
Input
This example uses the encounters example input. The expression memoizes a practitioner lookup so repeated practitioner IDs reuse the same search result within the current evaluation.
Example input
[
{
"encounterId": "enc-1001",
"patientId": "pat-0001",
"status": "finished",
"class": "outpatient",
"type": "primary-care",
"reason": "routine follow-up",
"facility": "ExampleCare Clinic",
"practitionerId": "prac-4001",
"start": "2026-02-14T09:30:00Z",
"end": "2026-02-14T10:05:00Z"
},
{
"encounterId": "enc-1002",
"patientId": "pat-0001",
"status": "finished",
"class": "outpatient",
"type": "imaging",
"reason": "headache evaluation",
"facility": "ExampleCare Imaging",
"practitionerId": "prac-4002",
"start": "2026-03-01T15:10:00Z",
"end": "2026-03-01T15:45:00Z"
},
{
"encounterId": "enc-1003",
"patientId": "pat-0001",
"status": "in-progress",
"class": "virtual",
"type": "care-coordination",
"reason": "medication questions",
"facility": "ExampleCare Clinic",
"practitionerId": "prac-4003",
"start": "2026-03-10T11:20:00Z",
"end": ""
},
{
"encounterId": "enc-1004",
"patientId": "pat-0001",
"status": "planned",
"class": "outpatient",
"type": "lab",
"reason": "fasting labs",
"facility": "ExampleCare Clinic",
"practitionerId": "prac-4001",
"start": "2026-03-20T08:00:00Z",
"end": ""
}
]
Expression
(
$loadPractitioner := $searchSingle.$memoize();
$.{
"encounterId": encounterId,
"practitionerId": $loadPractitioner(
"Practitioner",
{"identifier": "http://fhir.acme.health/identifier/practitioner-id|" & practitionerId}
).id
}
)
The first and fourth encounters both reference prac-4001, so the second lookup reuses the memoized result instead of repeating the search during the same evaluation.
Result
[
{
"encounterId": "enc-1001",
"practitionerId": "prac-4001"
},
{
"encounterId": "enc-1002",
"practitionerId": "prac-4002"
},
{
"encounterId": "enc-1003",
"practitionerId": "prac-4003"
},
{
"encounterId": "enc-1004",
"practitionerId": "prac-4001"
}
]