load method
Loads the record for stateId, from disk when persistent.
stateId is host-generated (cp-<12 hex>): anything else is
refused BEFORE it reaches the filesystem, so a client-controlled
id can never traverse out of dir via an absolute path or ../.
Implementation
Future<Map<String, Object?>?> load(String stateId) async {
if (!_stateIdPattern.hasMatch(stateId)) return null;
final cached = _memory[stateId];
if (cached != null) return cached;
if (dir != null) {
final file = File(p.join(dir!, '$stateId.json'));
if (await file.exists()) {
final record = (jsonDecode(await file.readAsString()) as Map)
.cast<String, Object?>();
_memory[stateId] = record;
return record;
}
}
return null;
}