mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-05-06 02:07:00 +00:00
Add LKGP cache exports and storage functions
This commit is contained in:
parent
08f1f05d58
commit
22656c8699
2 changed files with 29 additions and 0 deletions
|
|
@ -744,3 +744,30 @@ export async function resetCacheMetrics() {
|
|||
);
|
||||
return getCacheMetrics();
|
||||
}
|
||||
|
||||
// ──────────────── Last Known Good Provider (LKGP) ────────────────
|
||||
|
||||
export async function getLKGP(comboName: string, modelId: string): Promise<string | null> {
|
||||
const db = getDbInstance();
|
||||
const key = `lkgp:${comboName}:${modelId}`;
|
||||
const row = db
|
||||
.prepare("SELECT value FROM key_value WHERE namespace = 'lkgp' AND key = ?")
|
||||
.get(key);
|
||||
if (!row) return null;
|
||||
const record = toRecord(row);
|
||||
return typeof record.value === "string" ? record.value : null;
|
||||
}
|
||||
|
||||
export async function setLKGP(
|
||||
comboName: string,
|
||||
modelId: string,
|
||||
providerId: string
|
||||
): Promise<void> {
|
||||
const db = getDbInstance();
|
||||
const key = `lkgp:${comboName}:${modelId}`;
|
||||
db.prepare("INSERT OR REPLACE INTO key_value (namespace, key, value) VALUES ('lkgp', ?, ?)").run(
|
||||
key,
|
||||
providerId
|
||||
);
|
||||
backupDbFile("pre-write");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -158,6 +158,8 @@ export {
|
|||
getCachedSettings,
|
||||
getCachedPricing,
|
||||
getCachedProviderConnections,
|
||||
getCachedLKGP,
|
||||
setCachedLKGP,
|
||||
invalidateDbCache,
|
||||
} from "./db/readCache";
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue