mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-14 03:20:49 +00:00
38 lines
844 B
TypeScript
38 lines
844 B
TypeScript
import fs from "node:fs";
|
|
import { parseStrictNonNegativeInteger } from "../infra/parse-finite-number.js";
|
|
|
|
export function resolveCacheTtlMs(params: {
|
|
envValue: string | undefined;
|
|
defaultTtlMs: number;
|
|
}): number {
|
|
const { envValue, defaultTtlMs } = params;
|
|
if (envValue) {
|
|
const parsed = parseStrictNonNegativeInteger(envValue);
|
|
if (parsed !== undefined) {
|
|
return parsed;
|
|
}
|
|
}
|
|
return defaultTtlMs;
|
|
}
|
|
|
|
export function isCacheEnabled(ttlMs: number): boolean {
|
|
return ttlMs > 0;
|
|
}
|
|
|
|
export type FileStatSnapshot = {
|
|
mtimeMs: number;
|
|
sizeBytes: number;
|
|
};
|
|
|
|
export function getFileStatSnapshot(filePath: string): FileStatSnapshot | undefined {
|
|
try {
|
|
const stats = fs.statSync(filePath);
|
|
return {
|
|
mtimeMs: stats.mtimeMs,
|
|
sizeBytes: stats.size,
|
|
};
|
|
} catch {
|
|
return undefined;
|
|
}
|
|
}
|