//#region src/components/ticketBooking/utils/productCache.ts
/**
* 生成缓存键
* @param osKey - OS 实例的唯一标识
* @param cacheType - 缓存类型
*/
const generateCacheKey = (osKey, cacheType = "product") => {
	return `${cacheType}_cache_${osKey}`;
};
/**
* 通用缓存获取函数
* @param osKey - OS 实例的唯一标识
* @param cacheType - 缓存类型
* @param maxAge - 缓存最大有效期（毫秒），默认不限制
*/
const getCache = (osKey, cacheType = "product", maxAge) => {
	try {
		const cacheKey = generateCacheKey(osKey, cacheType);
		const cacheStr = localStorage.getItem(cacheKey);
		if (!cacheStr) return null;
		const cache = JSON.parse(cacheStr);
		if (maxAge && Date.now() - cache.timestamp > maxAge) {
			localStorage.removeItem(cacheKey);
			return null;
		}
		return cache.data;
	} catch (error) {
		console.error(`Failed to get ${cacheType} cache:`, error);
		return null;
	}
};
/**
* 从缓存中获取产品数据（兼容旧接口）
* @param osKey - OS 实例的唯一标识
* @param maxAge - 缓存最大有效期（毫秒），默认不限制
*/
const getProductCache = (osKey, maxAge) => {
	return getCache(osKey, "product", maxAge);
};
/**
* 通用缓存设置函数
* @param osKey - OS 实例的唯一标识
* @param data - 要缓存的数据
* @param cacheType - 缓存类型
*/
const setCache = (osKey, data, cacheType = "product") => {
	try {
		const cacheKey = generateCacheKey(osKey, cacheType);
		const cache = {
			data,
			timestamp: Date.now()
		};
		localStorage.setItem(cacheKey, JSON.stringify(cache));
	} catch (error) {
		console.error(`Failed to set ${cacheType} cache:`, error);
	}
};
/**
* 设置产品缓存数据（兼容旧接口）
* @param osKey - OS 实例的唯一标识
* @param data - 要缓存的数据
*/
const setProductCache = (osKey, data) => {
	setCache(osKey, data, "product");
};
/**
* 获取 BoardConfig 缓存
* @param osKey - OS 实例的唯一标识
* @param maxAge - 缓存最大有效期（毫秒），默认不限制
*/
const getBoardConfigCache = (osKey, maxAge) => {
	return getCache(osKey, "boardConfig", maxAge);
};
/**
* 设置 BoardConfig 缓存
* @param osKey - OS 实例的唯一标识
* @param data - 要缓存的数据
*/
const setBoardConfigCache = (osKey, data) => {
	setCache(osKey, data, "boardConfig");
};
//#endregion
exports.getBoardConfigCache = getBoardConfigCache;
exports.getCache = getCache;
exports.getProductCache = getProductCache;
exports.setBoardConfigCache = setBoardConfigCache;
exports.setCache = setCache;
exports.setProductCache = setProductCache;
