{"id":"510399e742be81dd","repo":"sindresorhus/got","slug":"cache-option-key-does-not-exist","errorCode":null,"errorMessage":"Cache option `${key}` does not exist","messagePattern":"Cache option `(.+?)` does not exist","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"source/core/options.ts","lineNumber":3162,"sourceCode":"\tget cacheOptions(): CacheOptions {\n\t\treturn this.#internals.cacheOptions;\n\t}\n\n\tset cacheOptions(value: CacheOptions) {\n\t\tassertPlainObject('cacheOptions', value);\n\n\t\tassertAny('cacheOptions.shared', [is.boolean, is.undefined], value.shared);\n\t\tassertAny('cacheOptions.cacheHeuristic', [is.number, is.undefined], value.cacheHeuristic);\n\t\tassertAny('cacheOptions.immutableMinTimeToLive', [is.number, is.undefined], value.immutableMinTimeToLive);\n\t\tassertAny('cacheOptions.ignoreCargoCult', [is.boolean, is.undefined], value.ignoreCargoCult);\n\n\t\tfor (const key of Object.keys(value)) {\n\t\t\tif (key === '__proto__') {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (!(key in this.#internals.cacheOptions)) {\n\t\t\t\tthrow new Error(`Cache option \\`${key}\\` does not exist`);\n\t\t\t}\n\t\t}\n\n\t\tif (this.#merging) {\n\t\t\tsafeObjectAssign(this.#internals.cacheOptions, value);\n\t\t} else {\n\t\t\tthis.#internals.cacheOptions = {...value};\n\t\t}\n\t}\n\n\t/**\n\tOptions for the advanced HTTPS API.\n\t*/\n\tget https(): HttpsOptions {\n\t\treturn this.#internals.https;\n\t}\n\n\tset https(value: HttpsOptions) {","sourceCodeStart":3144,"sourceCodeEnd":3180,"githubUrl":"https://github.com/sindresorhus/got/blob/e3924aa1e53a6ca3eb93a43618ce532442a89b40/source/core/options.ts#L3144-L3180","documentation":"Thrown by the `cacheOptions` setter when the object has a key that is not a recognized `http-cache-semantics` option. Valid keys are `shared`, `cacheHeuristic`, `immutableMinTimeToLive`, `ignoreCargoCult`. Unknown keys are rejected to prevent silently ineffective cache settings.","triggerScenarios":"Calling `got(url, {cacheOptions: {maxAge: 600}})` or any `cacheOptions` key outside the four supported ones. Passing top-level cache keys here instead of via the `cache` option also triggers it.","commonSituations":"Confusing `cacheOptions` (cache *semantics* tuning) with the `cache` option (the storage adapter); copying HTTP cache header names into `cacheOptions`.","solutions":["Use only `shared`, `cacheHeuristic`, `immutableMinTimeToLive`, `ignoreCargoCult` in `cacheOptions`.","For cache storage use the separate `cache` option, not `cacheOptions`.","Check the `${key}` in the message and remove/rename it."],"exampleFix":"// before\nawait got(url, {cacheOptions: {maxAge: 600}});\n// after\nawait got(url, {cacheOptions: {immutableMinTimeToLive: 600_000}});","handlingStrategy":"type-guard","validationCode":"const validCacheOptionKeys = new Set(['shared','cacheHeuristic','immutableMinTimeToLive','ignoreCargoCult']);\nfunction validateCacheOptions(co) {\n  for (const k of Object.keys(co ?? {})) {\n    if (!validCacheOptionKeys.has(k)) throw new Error(`Unknown cacheOptions key: ${k}`);\n  }\n}","typeGuard":"import type {CacheOptions} from 'got';\nfunction isCacheOptions(v: unknown): v is CacheOptions {\n  if (typeof v !== 'object' || v === null) return false;\n  return Object.keys(v).every(k => ['shared','cacheHeuristic','immutableMinTimeToLive','ignoreCargoCult','__proto__'].includes(k));\n}","tryCatchPattern":null,"preventionTips":["Remember `cacheOptions` tunes semantics; the storage adapter goes in `cache`.","Use the `CacheOptions` type to catch unknown keys at compile time."],"tags":["options","cache","validation","config"],"analyzedSha":"e3924aa1e53a6ca3eb93a43618ce532442a89b40","analyzedAt":"2026-08-03T19:22:24.770Z","schemaVersion":2}