put method
Store a module in the cache. Returns the integrity hash.
Implementation
String put(Module module) {
final bytes = module.writeToBuffer();
final hash = computeIntegrityFromBytes(bytes);
final path = _pathForHash(hash);
if (path == null) return hash;
final file = File(path);
if (file.existsSync()) return hash;
file.parent.createSync(recursive: true);
// Atomic write: temp file + rename.
final temp = File('$path.tmp.${pid}');
try {
temp.writeAsBytesSync(bytes);
temp.renameSync(path);
} catch (_) {
try {
temp.deleteSync();
} catch (_) {}
}
return hash;
}