2026-05-17 01:53:24 +09:00
|
|
|
import type { RuleFileCandidate } from "./types";
|
|
|
|
|
|
|
|
|
|
export type DirectoryScanEntry = {
|
|
|
|
|
path: string;
|
|
|
|
|
realPath: string;
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-18 14:13:51 +09:00
|
|
|
export type RuleScanCache = {
|
2026-05-17 01:53:24 +09:00
|
|
|
get: (key: string) => RuleFileCandidate[] | undefined;
|
|
|
|
|
set: (key: string, value: RuleFileCandidate[]) => void;
|
|
|
|
|
getDirScan: (dir: string) => DirectoryScanEntry[] | undefined;
|
|
|
|
|
setDirScan: (dir: string, entries: DirectoryScanEntry[]) => void;
|
2026-04-18 14:13:51 +09:00
|
|
|
clear: () => void;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export function createRuleScanCache(): RuleScanCache {
|
2026-05-17 01:53:24 +09:00
|
|
|
const finalResultCache = new Map<string, RuleFileCandidate[]>();
|
|
|
|
|
const directoryScanCache = new Map<string, DirectoryScanEntry[]>();
|
2026-04-18 14:13:51 +09:00
|
|
|
|
|
|
|
|
return {
|
2026-05-17 01:53:24 +09:00
|
|
|
get(key: string): RuleFileCandidate[] | undefined {
|
|
|
|
|
return finalResultCache.get(key);
|
|
|
|
|
},
|
|
|
|
|
set(key: string, value: RuleFileCandidate[]): void {
|
|
|
|
|
finalResultCache.set(key, value);
|
|
|
|
|
},
|
|
|
|
|
getDirScan(dir: string): DirectoryScanEntry[] | undefined {
|
|
|
|
|
return directoryScanCache.get(dir);
|
2026-04-18 14:13:51 +09:00
|
|
|
},
|
2026-05-17 01:53:24 +09:00
|
|
|
setDirScan(dir: string, entries: DirectoryScanEntry[]): void {
|
|
|
|
|
directoryScanCache.set(dir, entries);
|
2026-04-18 14:13:51 +09:00
|
|
|
},
|
|
|
|
|
clear(): void {
|
2026-05-17 01:53:24 +09:00
|
|
|
finalResultCache.clear();
|
|
|
|
|
directoryScanCache.clear();
|
2026-04-18 14:13:51 +09:00
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|