{"record":{"id":"08d98e14f473a800","repo":"withastro/astro","slug":"cache-set-was-called-but-caching-is-not-enable","errorCode":null,"errorMessage":"`cache.set()` was called but caching is not enabled. Configure a cache provider in your Astro config under `cache` to enable caching.","messagePattern":"`cache\\.set\\(\\)` was called but caching is not enabled\\. Configure a cache provider in your Astro config under `cache` to enable caching\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/astro/src/core/cache/runtime/noop.ts","lineNumber":50,"sourceCode":"/**\n * A no-op cache used when cache is not configured.\n * Logs a warning on first use instead of throwing, so libraries\n * can call cache methods without needing try/catch.\n * `invalidate()` still throws since it implies the caller\n * expects purging to actually work.\n */\nexport class DisabledAstroCache implements CacheLike {\n\treadonly enabled = false;\n\t#logger: AstroLogger | undefined;\n\n\tconstructor(logger?: AstroLogger) {\n\t\tthis.#logger = logger;\n\t}\n\n\t#warn(): void {\n\t\tif (!hasWarned) {\n\t\t\thasWarned = true;\n\t\t\tthis.#logger?.warn(\n\t\t\t\t'cache',\n\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","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/withastro/astro/blob/52e6c34790cc8ac4e69e6135ace06049867e5c4a/packages/astro/src/core/cache/runtime/noop.ts#L32-L68","documentation":"When no cache provider is configured, Astro injects a DisabledAstroCache no-op so Astro.cache / context.cache stay defined. The first cache.set() on that shim emits this one-time warning and every cache operation does nothing — caching requires a `cache.provider` entry in astro.config.","triggerScenarios":"Calling Astro.cache.set() in a route or context.cache.set() in middleware while astro.config has no cache block (or no cache.provider), e.g. only routeRules were configured.","commonSituations":"Following caching docs or copy-pasting cache code without adding the config block; environments whose configs diverge (cache configured in one env, missing in another); assuming routeRules alone enables caching.","solutions":["Add cache: { provider: { entrypoint: 'astro/cache/memory' } } to astro.config.mjs","Add routeRules entries (maxAge/swr/tags) so routes are actually cached","Or guard the call site with `if (Astro.cache.enabled)` when caching is optional"],"exampleFix":"// before — astro.config.mjs: routeRules but no provider\nexport default defineConfig({ routeRules: { '/**': { swr: 60 } } });\n\n// after — configure the provider\nexport default defineConfig({\n  cache: { provider: { entrypoint: 'astro/cache/memory' } },\n  routeRules: { '/**': { swr: 60 } },\n});","handlingStrategy":"type-guard","validationCode":"// fail fast in CI when cache code exists without a provider\nimport config from './astro.config.mjs';\nif (!config.cache?.provider) {\n  throw new Error('Astro.cache.set() will no-op: configure cache.provider');\n}","typeGuard":"// CacheLike exposes `enabled`: false on the no-op shim\nif (Astro.cache.enabled) {\n  await Astro.cache.set(/* ... */);\n}","tryCatchPattern":null,"preventionTips":["Configure cache.provider in the same PR that introduces cache.set() calls","Check Astro.cache.enabled before optional cache writes","Remember routeRules alone does not enable the cache — the provider does"],"tags":["cache","configuration","noop"],"backgroundTag":"cache-provider-not-configured","analyzedSha":"52e6c34790cc8ac4e69e6135ace06049867e5c4a","analyzedAt":"2026-08-18T18:48:03.901Z","contentChangedAt":"2026-08-18T18:48:03.901Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}