* Check if caching is enabled for this request. * Respects cache control headers and request params.
(body: Buffer | string, headers?: Record<string, string>)
| 143 | * Respects cache control headers and request params. |
| 144 | */ |
| 145 | shouldCache(body: Buffer | string, headers?: Record<string, string>): boolean { |
| 146 | if (!this.config.enabled) return false; |
| 147 | |
| 148 | // Respect Cache-Control: no-cache header |
| 149 | if (headers?.["cache-control"]?.includes("no-cache")) { |
| 150 | return false; |
| 151 | } |
| 152 | |
| 153 | // Check for explicit cache disable in body |
| 154 | try { |
| 155 | const parsed = JSON.parse(typeof body === "string" ? body : body.toString()); |
| 156 | if (parsed.cache === false || parsed.no_cache === true) { |
| 157 | return false; |
| 158 | } |
| 159 | } catch { |
| 160 | // Not JSON, allow caching |
| 161 | } |
| 162 | |
| 163 | return true; |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Get cached response if available and not expired. |
no outgoing calls
no test coverage detected