{"record":{"id":"63e1c6a7e891219f","repo":"withastro/astro","slug":"cachenotenabled-63e1c6","errorCode":"CacheNotEnabled","errorMessage":"`Astro.cache` is not available because the cache feature is not enabled. To use caching, configure a cache provider in your Astro config under `cache`.","messagePattern":"`Astro\\.cache` is not available because the cache feature is not enabled\\. To use caching, configure a cache provider in your Astro config under `cache`\\.","errorType":"exception","errorClass":"AstroError","httpStatus":null,"severity":"error","filePath":"packages/astro/src/core/cache/runtime/noop.ts","lineNumber":70,"sourceCode":"\t\t\t\t'`cache.set()` was called but caching is not enabled. Configure a cache provider in your Astro config under `cache` to enable caching.',\n\t\t\t);\n\t\t}\n\t}\n\n\tset(): void {\n\t\tthis.#warn();\n\t}\n\n\tget tags(): string[] {\n\t\treturn [];\n\t}\n\n\tget options(): Readonly<CacheOptions> {\n\t\treturn EMPTY_OPTIONS;\n\t}\n\n\tasync invalidate(): Promise<void> {\n\t\tthrow new AstroError(CacheNotEnabled);\n\t}\n}\n","sourceCodeStart":52,"sourceCodeEnd":73,"githubUrl":"https://github.com/withastro/astro/blob/d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca/packages/astro/src/core/cache/runtime/noop.ts#L52-L73","documentation":"When caching is not configured at all, Astro substitutes a `DisabledAstroCache` whose `set()` silently warns but whose `invalidate()` throws `CacheNotEnabled`. The design treats invalidation as a strict precondition: a caller that invalidates expects purging to actually happen, so a no-op would hide bugs. This is the dev/no-config counterpart to the provider-null case in `AstroCache`.","triggerScenarios":"Calling `Astro.cache.invalidate(...)` in a project with no `cache` entry in `astro.config`. The `DisabledAstroCache.invalidate` override at `noop.ts:70` always throws.","commonSituations":"Running a content site that uses `invalidate` in an endpoint but the user never added a cache provider; disabling cache temporarily for debugging while invalidation calls remain in shared middleware; integration code that assumes a cache is present.","solutions":["Configure a cache provider in `astro.config` under the `cache` key.","Gate invalidation behind `Astro.cache.enabled` so disabled-cache environments skip it.","Use `astro/cache/memory` for local/dev and an adapter provider for production."],"exampleFix":"// before\nawait Astro.cache.invalidate({ tags: ['home'] });\n\n// after\nif (Astro.cache.enabled) {\n  await Astro.cache.invalidate({ tags: ['home'] });\n}","handlingStrategy":"type-guard","validationCode":"if (!Astro.cache.enabled) { return; } // no-op in disabled mode","typeGuard":"function cacheActive(cache) { return cache && cache.enabled === true; }","tryCatchPattern":"try {\n  await Astro.cache.invalidate(...);\n} catch (e) {\n  if (e.code === 'CacheNotEnabled') { /* logging/no-op */ } else throw e;\n}","preventionTips":["Treat cache invalidation as optional in dev; guard with enabled.","Configure at least the memory provider in dev to mirror production behavior.","Keep invalidation calls in shared helpers that check enabled centrally."],"tags":["cache","configuration","runtime","dev"],"backgroundTag":null,"analyzedSha":"d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca","analyzedAt":"2026-08-12T13:37:29.035Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}