Home / Class/ RouteCache Class — astro Architecture

RouteCache Class — astro Architecture

Architecture documentation for the RouteCache class in route-cache.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  f2590c8b_da5c_804e_e7c6_accc3dae27c1["RouteCache"]
  2f0e5468_ae4d_5ec1_61b2_b1f585819620["route-cache.ts"]
  f2590c8b_da5c_804e_e7c6_accc3dae27c1 -->|defined in| 2f0e5468_ae4d_5ec1_61b2_b1f585819620
  8c5c9b0c_2e8b_04ef_47df_2d381271a123["constructor()"]
  f2590c8b_da5c_804e_e7c6_accc3dae27c1 -->|method| 8c5c9b0c_2e8b_04ef_47df_2d381271a123
  1045410a_b98f_bb64_b9ea_c72fdca1ad95["clearAll()"]
  f2590c8b_da5c_804e_e7c6_accc3dae27c1 -->|method| 1045410a_b98f_bb64_b9ea_c72fdca1ad95
  1908c3bf_4f4b_9edf_2e46_d7f8234fb45b["set()"]
  f2590c8b_da5c_804e_e7c6_accc3dae27c1 -->|method| 1908c3bf_4f4b_9edf_2e46_d7f8234fb45b
  5182e483_bd8d_1680_67cd_f665386c9d74["get()"]
  f2590c8b_da5c_804e_e7c6_accc3dae27c1 -->|method| 5182e483_bd8d_1680_67cd_f665386c9d74
  62817829_3a39_357e_33b8_9060451fad09["key()"]
  f2590c8b_da5c_804e_e7c6_accc3dae27c1 -->|method| 62817829_3a39_357e_33b8_9060451fad09

Relationship Graph

Source Code

packages/astro/src/core/render/route-cache.ts lines 89–122

export class RouteCache {
	private logger: Logger;
	private cache: Record<string, RouteCacheEntry> = {};
	private runtimeMode: RuntimeMode;

	constructor(logger: Logger, runtimeMode: RuntimeMode = 'production') {
		this.logger = logger;
		this.runtimeMode = runtimeMode;
	}

	/** Clear the cache. */
	clearAll() {
		this.cache = {};
	}

	set(route: RouteData, entry: RouteCacheEntry): void {
		const key = this.key(route);
		// NOTE: This shouldn't be called on an already-cached component.
		// Warn here so that an unexpected double-call of getStaticPaths()
		// isn't invisible and developer can track down the issue.
		if (this.runtimeMode === 'production' && this.cache[key]?.staticPaths) {
			this.logger.warn(null, `Internal Warning: route cache overwritten. (${key})`);
		}
		this.cache[key] = entry;
	}

	get(route: RouteData): RouteCacheEntry | undefined {
		return this.cache[this.key(route)];
	}

	key(route: RouteData) {
		return `${route.route}_${route.component}`;
	}
}

Domain

Frequently Asked Questions

What is the RouteCache class?
RouteCache is a class in the astro codebase, defined in packages/astro/src/core/render/route-cache.ts.
Where is RouteCache defined?
RouteCache is defined in packages/astro/src/core/render/route-cache.ts at line 89.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free