"""Caching to avoid duplicate requests.""" from typing import Dict, Optional import hashlib _cache: Dict[str, any] = {} def get_cache_key(url: str) -> str: """Generate cache key from URL.""" return hashlib.md5(url.encode()).hexdigest() def get_cached(url: str) -> Optional[any]: """Get cached response.""" return _cache.get(get_cache_key(url)) def set_cached(url: str, data: any): """Cache response.""" _cache[get_cache_key(url)] = data def clear_cache(): """Clear all cached data.""" _cache.clear()