# Get the cached value (None if it doesn't exist)
async def get_cache(key: str) -> Optional[Dict[str, Any]]:
try:
async with aiofiles.open("cache.json", 'r') as f:
cache_content = await f.read()
parsed = json.loads(cache_content)
return parsed.get(key)
except (FileNotFoundError, json.JSONDecodeError):
return None
# Set the cache value
async def set_cache(key: str, value: Dict[str, Any]) -> None:
try:
async with aiofiles.open("cache.json", 'r') as f:
cache_content = await f.read()
parsed = json.loads(cache_content)
except (FileNotFoundError, json.JSONDecodeError):
parsed = {}
parsed[key] = value
async with aiofiles.open("cache.json", 'w') as f:
await f.write(json.dumps(parsed))