isCached method
Check if a step with the given fingerprint has been cached.
Returns true if the cache entry exists and its outputs are still valid.
Implementation
Future<bool> isCached(NativeStepFingerprint fingerprint) async {
final metaFile = _metaFile(fingerprint);
if (!metaFile.existsSync()) {
logger?.fine('Cache miss for ${fingerprint.id} (no metadata)');
return false;
}
try {
final json =
jsonDecode(await metaFile.readAsString()) as Map<String, dynamic>;
final cachedHash = json['hash'] as String?;
if (cachedHash != fingerprint.hash) {
logger?.fine(
'Cache miss for ${fingerprint.id}: '
'hash mismatch (cached=$cachedHash, current=${fingerprint.hash})',
);
return false;
}
// Verify all recorded output files still exist
final outputs = (json['outputs'] as List<dynamic>?) ?? [];
for (final output in outputs) {
final path = output as String;
if (!File(path).existsSync()) {
logger?.fine(
'Cache miss for ${fingerprint.id}: output missing at $path',
);
return false;
}
}
logger?.fine('Cache hit for ${fingerprint.id}');
return true;
} catch (e) {
logger?.warning('Cache read error for ${fingerprint.id}: $e');
return false;
}
}