Initial commit with translated description

This commit is contained in:
2026-03-29 08:34:04 +08:00
commit 80ef0a90d7
24 changed files with 4556 additions and 0 deletions

25
exec_cache.js Normal file
View File

@@ -0,0 +1,25 @@
const { exec } = require('child_process');
// Optimization: Cache executive outcomes to reduce repetitive exec calls
const EXEC_CACHE = new Map();
const EXEC_CACHE_TTL = 60000; // 1 minute
function cachedExec(command, callback) {
const now = Date.now();
if (EXEC_CACHE.has(command)) {
const cached = EXEC_CACHE.get(command);
if (now - cached.timestamp < EXEC_CACHE_TTL) {
// Return cached result asynchronously to mimic exec behavior
return process.nextTick(() => {
callback(cached.error, cached.stdout, cached.stderr);
});
}
}
exec(command, { windowsHide: true }, (error, stdout, stderr) => {
EXEC_CACHE.set(command, { timestamp: Date.now(), error, stdout, stderr });
callback(error, stdout, stderr);
});
}
module.exports = { cachedExec };