var cache = /* @__PURE__ */ new Map();
/**
* Return cached data if fresh (within TTL), or `undefined` if stale/missing.
* `undefined` is the cache-miss sentinel — we never store `undefined` as a value
* (cached null/empty-list are valid results from a successful-but-empty lookup).
*/
function getCached(key) {
	const entry = cache.get(key);
	if (!entry) return void 0;
	if (Date.now() - entry.fetchedAt > 3e5) return void 0;
	return entry.data;
}
/** Return cached data regardless of TTL (stale fallback for failed fetches). */
function getStaleCached(key) {
	const entry = cache.get(key);
	return entry ? entry.data : void 0;
}
/** Store data with `fetchedAt = Date.now()`. */
function setCached(key, data) {
	cache.set(key, {
		data,
		fetchedAt: Date.now()
	});
}
/** Clear ALL cache entries — called by the "Check for updates" refresh trigger. */
function invalidateVersionCache() {
	cache.clear();
}
/**
* Cache-first lookup with stale-on-error fallback.
*
* 1. If a fresh cache entry exists, return it (no upstream call).
* 2. Otherwise, call `fetcher`. On success, cache + return the result.
* 3. On failure, return the stale cached value if one exists, else `undefined`
*    (the caller applies its own default — `null` / `[]` — for the no-data case).
*
* The fetcher SHOULD throw on failure so the stale fallback can engage; a
* successful-but-empty result (null, `[]`) is cached as-is so a consistently
* empty lookup is not re-fetched every call.
*/
async function withCache(key, fetcher) {
	const fresh = getCached(key);
	if (fresh !== void 0) return fresh;
	try {
		const data = await fetcher();
		setCached(key, data);
		return data;
	} catch {
		return getStaleCached(key);
	}
}

export { invalidateVersionCache as i, withCache as w };
//# sourceMappingURL=version-cache-CSnmLqxQ.js.map
