Files
Sergei Zharinov 930cf6633c refactor: Rewrite imports with .ts extensions (#40700)
fix: Additional vi.mock path corrections and prettier formatting
2026-01-26 22:48:17 +00:00

39 lines
1.1 KiB
TypeScript

import { logger } from '../../../../logger/index.ts';
import {
cachePathExists,
outputCacheFile,
readCacheFile,
} from '../../../fs/index.ts';
import { getLocalCacheFileName } from '../common.ts';
import type { RepoCacheRecord } from '../schema.ts';
import { RepoCacheBase } from './base.ts';
export class RepoCacheLocal extends RepoCacheBase {
constructor(repository: string, fingerprint: string) {
super(repository, fingerprint);
}
protected async read(): Promise<string | null> {
const cacheFileName = this.getCacheFileName();
try {
// suppress debug logs with errors
if (!(await cachePathExists(cacheFileName))) {
return null;
}
return await readCacheFile(cacheFileName, 'utf8');
} catch (err) {
logger.debug({ err, cacheFileName }, 'Repository local cache not found');
}
return null;
}
protected async write(data: RepoCacheRecord): Promise<void> {
const cacheFileName = this.getCacheFileName();
await outputCacheFile(cacheFileName, JSON.stringify(data));
}
private getCacheFileName(): string {
return getLocalCacheFileName(this.platform, this.repository);
}
}