{"record":{"id":"6e31b8b3abee9d9f","repo":"gohugoio/hugo","slug":"q-is-not-a-valid-cache-name","errorCode":null,"errorMessage":"%q is not a valid cache name","messagePattern":"%q is not a valid cache name","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cache/filecache/filecache_config.go","lineNumber":226,"sourceCode":"func DecodeConfig(fs afero.Fs, bcfg config.BaseConfig, m map[string]any) (Configs, error) {\n\tc := make(Configs)\n\tvalid := make(map[string]bool)\n\t// Add defaults\n\tfor k, v := range defaultCacheConfigs {\n\t\tc[k] = v\n\t\tvalid[k] = true\n\t}\n\n\t_, isOsFs := fs.(*afero.OsFs)\n\n\tfor k, v := range m {\n\t\tif _, ok := v.(hmaps.Params); !ok {\n\t\t\tcontinue\n\t\t}\n\t\tvar ok bool\n\t\tcc, ok := c[k]\n\t\tif !ok {\n\t\t\treturn nil, fmt.Errorf(\"%q is not a valid cache name\", k)\n\t\t}\n\n\t\tdc := &mapstructure.DecoderConfig{\n\t\t\tResult:           &cc,\n\t\t\tDecodeHook:       mapstructure.StringToTimeDurationHookFunc(),\n\t\t\tWeaklyTypedInput: true,\n\t\t}\n\n\t\tdecoder, err := mapstructure.NewDecoder(dc)\n\t\tif err != nil {\n\t\t\treturn c, err\n\t\t}\n\n\t\tif err := decoder.Decode(v); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to decode filecache config: %w\", err)\n\t\t}\n\n\t\tif cc.Dir == \"\" {","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/cache/filecache/filecache_config.go#L208-L244","documentation":"Hugo's file cache supports a fixed set of named caches: images, assets, modules, modulequeries, modulegitinfo, getresource, and misc (filecache_config.go:39-46). DecodeConfig iterates the user's caches config map and rejects any key not in this predefined set (filecache_config.go:225-226).","triggerScenarios":"Adding a custom or misspelled entry under caches: in the config file, e.g. caches:image: or caches:mycache:.","commonSituations":"Typo in a cache name; attempting to define a custom named cache (unsupported); YAML key casing or indentation errors.","solutions":["Correct the cache name to match one of the valid keys (images, assets, modules, modulequeries, modulegitinfo, getresource, misc)","Remove the unknown cache entry from the config","Consult Hugo docs for the list of configurable cache names"],"exampleFix":"# before (hugo.toml)\n[caches.image]\nmaxAge = \"24h\"\ndir = \":cacheDir/images\"\n# after\ncaches:\n  images:\n    maxAge: '24h'\n    dir: ':cacheDir/images'","handlingStrategy":"validation","validationCode":"// Validate cache names against the known set before deploying config.\nvar validCacheKeys = map[string]bool{\n    \"images\": true, \"assets\": true, \"modules\": true,\n    \"modulequeries\": true, \"modulegitinfo\": true,\n    \"getresource\": true, \"misc\": true,\n}\nfunc validateCacheNames(m map[string]any) error {\n    for k := range m {\n        if !validCacheKeys[k] {\n            return fmt.Errorf(\"%q is not a valid cache name\", k)\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Restrict caches: entries to the seven documented cache names","Run hugo config to validate config after editing cache settings","Keep a reference of valid cache names handy when editing config"],"tags":["cache","filecache","config","validation","hugo"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}