mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-06 07:12:12 +03:00
chore: remove unused semantic cache maintenance exports (#5334)
Verified dead-code removal: merged result passes typecheck:core + 194 affected unit tests + ESLint clean. Integrated into release/v3.8.41. Thanks @JxnLexn for the cleanup!
This commit is contained in:
@@ -116,7 +116,13 @@ function getMemoryCache() {
|
||||
* @param {string} [apiKeyId] - API key ID for per-key isolation (prevents cross-user cache hits)
|
||||
* @returns {string} hex signature
|
||||
*/
|
||||
export function generateSignature(model, conversation, temperature = 0, topP = 1, apiKeyId?: string) {
|
||||
export function generateSignature(
|
||||
model,
|
||||
conversation,
|
||||
temperature = 0,
|
||||
topP = 1,
|
||||
apiKeyId?: string
|
||||
) {
|
||||
const payload = JSON.stringify({
|
||||
model,
|
||||
messages: normalizeConversation(conversation),
|
||||
@@ -315,48 +321,6 @@ export function invalidateStale(maxAgeMs: number): number {
|
||||
}
|
||||
}
|
||||
|
||||
// ── Auto-cleanup timer ──
|
||||
|
||||
let _cleanupTimer: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
/**
|
||||
* Start periodic auto-cleanup of expired entries.
|
||||
* @param {number} intervalMs - Cleanup interval (default: 5 minutes)
|
||||
*/
|
||||
export function startAutoCleanup(intervalMs = 300_000): void {
|
||||
stopAutoCleanup();
|
||||
_cleanupTimer = setInterval(() => {
|
||||
const removed = cleanExpiredEntries();
|
||||
if (removed > 0) {
|
||||
console.log(`[SemanticCache] Auto-cleaned ${removed} expired entries`);
|
||||
}
|
||||
}, intervalMs);
|
||||
if (_cleanupTimer && typeof _cleanupTimer === "object" && "unref" in _cleanupTimer) {
|
||||
(_cleanupTimer as { unref?: () => void }).unref?.();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop periodic auto-cleanup.
|
||||
*/
|
||||
export function stopAutoCleanup(): void {
|
||||
if (_cleanupTimer) {
|
||||
clearInterval(_cleanupTimer);
|
||||
_cleanupTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
export function cleanOldMetrics(retentionDays = 90): number {
|
||||
try {
|
||||
const db = getDbInstance();
|
||||
const cutoff = new Date(Date.now() - retentionDays * 86400000).toISOString();
|
||||
const result = db.prepare("DELETE FROM semantic_cache WHERE created_at < ?").run(cutoff);
|
||||
return result.changes || 0;
|
||||
} catch {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all cache entries.
|
||||
*/
|
||||
|
||||
@@ -6,7 +6,15 @@ import {
|
||||
isCacheableForWrite,
|
||||
} from "../../src/lib/semanticCache.ts";
|
||||
|
||||
const semanticCachePublicApi = await import("../../src/lib/semanticCache.ts");
|
||||
|
||||
describe("Semantic Cache", () => {
|
||||
it("public surface excludes unused maintenance timer helpers", () => {
|
||||
assert.equal("startAutoCleanup" in semanticCachePublicApi, false);
|
||||
assert.equal("stopAutoCleanup" in semanticCachePublicApi, false);
|
||||
assert.equal("cleanOldMetrics" in semanticCachePublicApi, false);
|
||||
});
|
||||
|
||||
describe("generateSignature", () => {
|
||||
it("generates consistent signatures for same inputs", () => {
|
||||
const messages = [{ role: "user", content: "hello" }];
|
||||
@@ -77,7 +85,11 @@ describe("Semantic Cache", () => {
|
||||
const messages = [{ role: "user", content: "what is 2+2?" }];
|
||||
const sigKeyA = generateSignature("gpt-4o", messages, 0, 1, "key-id-alice");
|
||||
const sigKeyB = generateSignature("gpt-4o", messages, 0, 1, "key-id-bob");
|
||||
assert.notEqual(sigKeyA, sigKeyB, "different API keys must produce different cache signatures");
|
||||
assert.notEqual(
|
||||
sigKeyA,
|
||||
sigKeyB,
|
||||
"different API keys must produce different cache signatures"
|
||||
);
|
||||
});
|
||||
|
||||
it("generates consistent signatures for same API key ID (#3740)", () => {
|
||||
|
||||
Reference in New Issue
Block a user