| 46 | return (0, crypto_1.createHash)("sha256").update(composite).digest("hex"); |
| 47 | } |
| 48 | class MemoryCache { |
| 49 | store = new Map(); |
| 50 | async get(key) { |
| 51 | const e = this.store.get(key); |
| 52 | if (!e) |
| 53 | return null; |
| 54 | if (e.expires_at < Date.now()) { |
| 55 | this.store.delete(key); |
| 56 | return null; |
| 57 | } |
| 58 | return e; |
| 59 | } |
| 60 | async put(key, _prompt, _model, value, ttl_ms, usage) { |
| 61 | const now = Date.now(); |
| 62 | this.store.set(key, { |
| 63 | value, |
| 64 | prompt_tokens: usage.prompt_tokens ?? null, |
| 65 | completion_tokens: usage.completion_tokens ?? null, |
| 66 | cost_usd: usage.cost_usd ?? null, |
| 67 | cached_at: now, |
| 68 | expires_at: now + ttl_ms, |
| 69 | }); |
| 70 | } |
| 71 | } |
| 72 | class PgCache { |
| 73 | async get(key) { |
| 74 | // Lazy import — keeps tests that don't exercise PG mode free of pg dependency. |
nothing calls this directly
no outgoing calls
no test coverage detected