{"record":{"id":"7c36acd044376a67","repo":"getgrav/grav","slug":"cache-folder-not-defined","errorCode":null,"errorMessage":"Cache folder not defined.","messagePattern":"Cache folder not defined\\.","errorType":"exception","errorClass":"BadMethodCallException","httpStatus":null,"severity":"error","filePath":"system/src/Grav/Common/Config/CompiledBase.php","lineNumber":61,"sourceCode":"    /** @var array  List of files to load. */\n    protected $files;\n\n    /** @var string */\n    protected $path;\n\n    /** @var mixed  Configuration object. */\n    protected $object;\n\n    /**\n     * @param  string $cacheFolder  Cache folder to be used.\n     * @param  array  $files  List of files as returned from ConfigFileFinder class.\n     * @param string $path  Base path for the file list.\n     * @throws BadMethodCallException\n     */\n    public function __construct($cacheFolder, array $files, $path)\n    {\n        if (!$cacheFolder) {\n            throw new BadMethodCallException('Cache folder not defined.');\n        }\n\n        $this->path = $path ? rtrim($path, '\\\\/') . '/' : '';\n        $this->cacheFolder = $cacheFolder;\n        $this->files = $files;\n    }\n\n    /**\n     * Get filename for the compiled PHP file.\n     *\n     * @param string|null $name\n     * @return $this\n     */\n    public function name($name = null)\n    {\n        if (!$this->name) {\n            $this->name = $name ?: md5(json_encode(array_keys($this->files)));\n        }","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/getgrav/grav/blob/6040efed04efa69b8209448ed81308e7c24147c2/system/src/Grav/Common/Config/CompiledBase.php#L43-L79","documentation":"CompiledBase is the parent of CompiledConfig, CompiledBlueprints and CompiledLanguages — the classes that compile and cache Grav's YAML configuration into PHP files. Its constructor requires a non-empty $cacheFolder (normally resolved from the cache:// stream, e.g. cache://compiled/config) and throws BadMethodCallException if it is empty. An empty folder means the resource locator could not resolve the cache stream to a real path, so there is nowhere to write the compiled file.","triggerScenarios":"Constructing new CompiledConfig('', $files, $path) (or the blueprints/languages siblings) with an empty folder; the locator returning false from findResource('cache://compiled/config', true, true) because the cache stream or its target directory is broken; a plugin building one of these classes without resolving the stream first.","commonSituations":"streams.schemes cache entry misconfigured or removed in user/config; the cache directory cannot be created due to permissions so findResource fails; a custom or environment-specific setup (multi-site) where cache:// points at an invalid path; code that assumes the stream always resolves.","solutions":["Resolve the folder from the locator and check it before constructing: $cache = $grav['locator']->findResource('cache://compiled/config', true, true); if (!$cache) fail with context","Verify the cache stream in streams.schemes and that the cache/ directory exists and is writable by the web user","Clear the compiled caches (rm -rf cache/*) after fixing stream config so stale state does not persist","For custom compiled classes, default the folder to a known path like GRAV_ROOT . '/cache/compiled' when the stream lookup fails intentionally"],"exampleFix":"// before\n$compiled = new CompiledConfig($cache, $files, GRAV_ROOT); // $cache === false cast to ''\n\n// after\n$cache = $locator->findResource('cache://compiled/config', true, true);\nif (!$cache) {\n    throw new RuntimeException('cache:// stream could not be resolved; check streams config and cache dir permissions');\n}\n$compiled = new CompiledConfig($cache, $files, GRAV_ROOT);","handlingStrategy":"validation","validationCode":"$cache = $grav['locator']->findResource('cache://compiled/config', true, true);\nif (!$cache) {\n    throw new RuntimeException('cache:// stream unresolvable — check streams.schemes and cache dir permissions');\n}\n$compiled = new CompiledConfig($cache, $files, GRAV_ROOT);","typeGuard":null,"tryCatchPattern":"try {\n    $compiled = new CompiledConfig($cache, $files, GRAV_ROOT);\n} catch (BadMethodCallException $e) {\n    // cacheFolder came back empty — the locator could not resolve cache://\n    throw new RuntimeException('Compiled config needs a resolvable cache folder: ' . $e->getMessage(), 0, $e);\n}","preventionTips":["Never construct Compiled* classes with an unchecked findResource() result — it returns false on failure","Keep the cache stream defined and its directory writable by the web user","Purge cache/ after changing stream configuration to rebuild from a known-good state"],"tags":["grav","configuration","cache","stream-wrapper","badmethodcallexception"],"backgroundTag":"missing-cache-directory","analyzedSha":"6040efed04efa69b8209448ed81308e7c24147c2","analyzedAt":"2026-08-17T05:07:31.593Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}