withastro/astro · warning

`cache.set()` was called but caching is not enabled. Configu

Error message

`cache.set()` was called but caching is not enabled. Configure a cache provider in your Astro config under `cache` to enable caching.

What it means

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.

Source

Thrown at packages/astro/src/core/cache/runtime/noop.ts:50

/**
 * A no-op cache used when cache is not configured.
 * Logs a warning on first use instead of throwing, so libraries
 * can call cache methods without needing try/catch.
 * `invalidate()` still throws since it implies the caller
 * expects purging to actually work.
 */
export class DisabledAstroCache implements CacheLike {
	readonly enabled = false;
	#logger: AstroLogger | undefined;

	constructor(logger?: AstroLogger) {
		this.#logger = logger;
	}

	#warn(): void {
		if (!hasWarned) {
			hasWarned = true;
			this.#logger?.warn(
				'cache',
				'`cache.set()` was called but caching is not enabled. Configure a cache provider in your Astro config under `cache` to enable caching.',
			);
		}
	}

	set(): void {
		this.#warn();
	}

	get tags(): string[] {
		return [];
	}

	get options(): Readonly<CacheOptions> {
		return EMPTY_OPTIONS;
	}

View on GitHub (pinned to 52e6c34790)

Solutions

  1. Add cache: { provider: { entrypoint: 'astro/cache/memory' } } to astro.config.mjs
  2. Add routeRules entries (maxAge/swr/tags) so routes are actually cached
  3. Or guard the call site with `if (Astro.cache.enabled)` when caching is optional

Example fix

// before — astro.config.mjs: routeRules but no provider
export default defineConfig({ routeRules: { '/**': { swr: 60 } } });

// after — configure the provider
export default defineConfig({
  cache: { provider: { entrypoint: 'astro/cache/memory' } },
  routeRules: { '/**': { swr: 60 } },
});
Defensive patterns

Strategy: type-guard

Validate before calling

// fail fast in CI when cache code exists without a provider
import config from './astro.config.mjs';
if (!config.cache?.provider) {
  throw new Error('Astro.cache.set() will no-op: configure cache.provider');
}

Type guard

// CacheLike exposes `enabled`: false on the no-op shim
if (Astro.cache.enabled) {
  await Astro.cache.set(/* ... */);
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of withastro/astro@52e6c34790 (2026-08-18). Data as JSON: /api/errors/08d98e14f473a800. Report an issue: GitHub.