Chore: add cache key to fs cache

This commit is contained in:
SukkaW
2024-08-04 23:13:23 +08:00
parent 32ef8ef7b6
commit f761546a05
7 changed files with 85 additions and 16 deletions

View File

@@ -6,6 +6,8 @@ import { mkdirSync } from 'fs';
import picocolors from 'picocolors';
import { fastStringArrayJoin } from './misc';
import { performance } from 'perf_hooks';
import fs from 'fs';
import { stringHash } from './string-hash';
const identity = (x: any) => x;
@@ -213,3 +215,8 @@ export const serializeSet = (set: Set<string>) => fastStringArrayJoin(Array.from
export const deserializeSet = (str: string) => new Set(str.split(separator));
export const serializeArray = (arr: string[]) => fastStringArrayJoin(arr, separator);
export const deserializeArray = (str: string) => str.split(separator);
export const createCacheKey = (filename: string) => {
const fileHash = stringHash(fs.readFileSync(filename, 'utf-8'));
return (key: string) => key + '$' + fileHash;
};