Skip to content

A one-of-a-kind resume builder that keeps your privacy in mind. Completely secure, customizable, portable, open-source and free forever. Try it out today!

910 B
Raw Blame
import type { CompileStylesheetResult } from "./types";

const MAX_ENTRIES = 128;
const cache = new Map<string, CompileStylesheetResult>();

export function getCachedStylesheet(key: string): CompileStylesheetResult | undefined {
	const value = cache.get(key);
	if (value === undefined) return;
	cache.delete(key);
	cache.set(key, value);
	return value;
}

export function setCachedStylesheet(key: string, value: CompileStylesheetResult): void {
	cache.delete(key);
	cache.set(key, value);
	while (cache.size > MAX_ENTRIES) {
		const oldestKey = cache.keys().next().value;
		if (oldestKey === undefined) break;
		cache.delete(oldestKey);
	}
}

const SEMANTIC_CSS_COMPILER_BUILD_ID = "semantic-css-v1-values-2";

export function stylesheetCacheKey(languageVersion: number, source: string, registry: string): string {
	return JSON.stringify([languageVersion, source, SEMANTIC_CSS_COMPILER_BUILD_ID, registry]);
}