MCPcopy
hub / github.com/BlockRunAI/ClawRouter / shouldCache

Method shouldCache

src/response-cache.ts:145–164  ·  view source on GitHub ↗

* Check if caching is enabled for this request. * Respects cache control headers and request params.

(body: Buffer | string, headers?: Record<string, string>)

Source from the content-addressed store, hash-verified

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.

Calls

no outgoing calls

Tested by

no test coverage detected