/**
 * 设置时效缓存
 * @param key 缓存key值
 * @param value 缓存数据
 */
export async function setStorageSyncSecond<T>(key: string, value: T) {
	window.localStorage.setItem(key, JSON.stringify(value));
}

/**
 * 读取缓存，若缓存不存在，返回null
 * @param key 缓存key
 */
export function getStorageSyncTime<T>(key: string): T | undefined {
	const dataStr = window.localStorage.getItem(key);

	if (dataStr === null) {
		return undefined;
	}

	try {
		return JSON.parse(dataStr) as T;
	} catch (error) {
		console.error('Failed to parse cached data:', error);
		return undefined;
	}
}
