{"record":{"id":"295cb6361bb5fef0","repo":"cakephp/cakephp","slug":"invalid-cache-time-value-s","errorCode":null,"errorMessage":"Invalid cache time value `%s`","messagePattern":"Invalid cache time value `(.+?)`","errorType":"exception","errorClass":"CakeException","httpStatus":null,"severity":"error","filePath":"src/Routing/Middleware/AssetMiddleware.php","lineNumber":164,"sourceCode":"     * @param \\Psr\\Http\\Message\\ServerRequestInterface $request The request object to use.\n     * @param \\SplFileInfo $file The file wrapper for the file.\n     * @return \\Cake\\Http\\Response The response with the file & headers.\n     */\n    protected function deliverAsset(ServerRequestInterface $request, SplFileInfo $file): Response\n    {\n        $resource = fopen($file->getPathname(), 'rb');\n        if ($resource === false) {\n            throw new CakeException(sprintf('Cannot open resource `%s`', $file->getPathname()));\n        }\n        $stream = new Stream($resource);\n\n        $response = new Response(['stream' => $stream]);\n\n        $contentType = MimeType::getMimeTypeForFile($file->getRealPath());\n        $modified = $file->getMTime();\n        $expire = strtotime($this->cacheTime);\n        if ($expire === false) {\n            throw new CakeException(sprintf('Invalid cache time value `%s`', $this->cacheTime));\n        }\n\n        $now = time();\n        $maxAge = $expire - $now;\n\n        return $response\n            ->withHeader('Content-Type', $contentType)\n            ->withHeader('Cache-Control', 'public,max-age=' . $maxAge)\n            ->withHeader('Date', DateTime::parse($now)->toRfc7231String())\n            ->withHeader('Last-Modified', DateTime::parse($modified)->toRfc7231String())\n            ->withHeader('Expires', DateTime::parse($expire)->toRfc7231String());\n    }\n}\n","sourceCodeStart":146,"sourceCodeEnd":178,"githubUrl":"https://github.com/cakephp/cakephp/blob/1128eba9b09f1946df684811350e26f2cef68fac/src/Routing/Middleware/AssetMiddleware.php#L146-L178","documentation":"AssetMiddleware's deliverAsset() parses the configured cacheTime string with strtotime() to compute an Expires header. When strtotime() cannot parse the value it returns false, meaning the middleware's cacheTime option is not a valid strtotime() expression. CakePHP throws this to fail fast rather than emit bogus cache headers.","triggerScenarios":"Setting the 'cacheTime' option on AssetMiddleware to a string strtotime() cannot parse, e.g. 'in 1 day', '+1w eek', an integer-like overflow string, or an empty string.","commonSituations":"Typos in the cacheTime config in middleware definition; copying '+1 week' as '1 week +'; using locale-formatted dates strtotime can't parse; passing a relative time from an env var that was mangled.","solutions":["Fix the cacheTime option to a valid strtotime() string, e.g. '+1 day', '+2 weeks', '+1 month'.","If config comes from environment/config file, validate it with strtotime($value) !== false at bootstrap and fail early.","If a fixed timestamp is desired, pre-compute with strtotime() before passing it in."],"exampleFix":"// before\nnew AssetMiddleware(['cacheTime' => 'in one day']);\n// after\nnew AssetMiddleware(['cacheTime' => '+1 day']);","handlingStrategy":"validation","validationCode":"$cacheTime = '+1 day';\nif (strtotime($cacheTime) === false) {\n    throw new InvalidArgumentException(\"cacheTime must be a valid strtotime() expression, got '$cacheTime'\");\n}","typeGuard":"function isStrToTimeable(string $value): bool { return strtotime($value) !== false; }","tryCatchPattern":null,"preventionTips":["Only pass strtotime()-compatible strings like '+1 day', '+2 weeks', '+1 month'.","Validate cacheTime from env/config at bootstrap before wiring middleware.","Add a unit test that constructs AssetMiddleware with the configured cacheTime."],"tags":["php","cakephp","middleware","caching","invalid-config-value"],"backgroundTag":"invalid-config-value","analyzedSha":"1128eba9b09f1946df684811350e26f2cef68fac","analyzedAt":"2026-09-12T12:07:00.388Z","contentChangedAt":"2026-09-12T12:07:00.388Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}