save method
Snapshots the live cache paths into the cache root and writes a fresh manifest.
A no-op when caching is disabled. Best-effort: paths that cannot be read are skipped silently. Honors CubeResourceLimits.diskBytes by pruning the oldest sibling cache entries until the total fits.
Implementation
Future<void> save() async {
if (!spec.cache.enabled) return;
await _env.remove('$cacheRoot/cache', recursive: true, force: true);
for (final path in spec.cache.paths) {
final relative = _mirrorRelative(path);
await _copyTree('${_env.cwd}/$relative', '$cacheRoot/cache/$relative');
}
final ttl = spec.cache.ttl;
await _env.writeFile(
'$cacheRoot/manifest.json',
jsonEncode({
'key': cacheKey,
'name': spec.name,
'createdAtMs': DateTime.now().millisecondsSinceEpoch,
if (ttl != null) 'ttlMs': ttl.inMilliseconds,
'paths': spec.cache.paths,
}),
);
await _pruneToBound();
}