* Generate cache key from request body. * Hashes: model + messages + temperature + max_tokens + other params
(body: Buffer | string)
| 125 | * Hashes: model + messages + temperature + max_tokens + other params |
| 126 | */ |
| 127 | static generateKey(body: Buffer | string): string { |
| 128 | try { |
| 129 | const parsed = JSON.parse(typeof body === "string" ? body : body.toString()); |
| 130 | const normalized = normalizeForCache(parsed); |
| 131 | const canonical = canonicalize(normalized); |
| 132 | const keyContent = JSON.stringify(canonical); |
| 133 | return createHash("sha256").update(keyContent).digest("hex").slice(0, 32); |
| 134 | } catch { |
| 135 | // Fallback: hash raw body |
| 136 | const content = typeof body === "string" ? body : body.toString(); |
| 137 | return createHash("sha256").update(content).digest("hex").slice(0, 32); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Check if caching is enabled for this request. |
no test coverage detected