in src/lib/server/providers/index.ts [39:65]
async function readCache(): Promise<MaxTokensCache> {
if (memoryCache) {
return memoryCache;
}
if (cacheReadPromise) {
return cacheReadPromise;
}
cacheReadPromise = (async () => {
try {
const data = await fs.readFile(CACHE_FILE_PATH, "utf-8");
memoryCache = JSON.parse(data) as MaxTokensCache;
return memoryCache!;
} catch (error: unknown) {
if (typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT") {
console.warn(`Cache file not found at ${CACHE_FILE_PATH}, starting with empty cache.`);
memoryCache = {};
return {};
}
console.error("Error reading context length cache file:", error);
memoryCache = {};
return {};
} finally {
cacheReadPromise = null;
}
})();
return cacheReadPromise;
}