| from datetime import datetime, timedelta | |
| import uuid | |
| # Simple in-memory cache (replace with Redis in production) | |
| result_cache = {} | |
| CACHE_EXPIRY_HOURS = 1 | |
| def store_result(data): | |
| cache_id = str(uuid.uuid4()) | |
| expiry = datetime.now() + timedelta(hours=CACHE_EXPIRY_HOURS) | |
| result_cache[cache_id] = { | |
| 'data': data, | |
| 'expiry': expiry | |
| } | |
| return cache_id | |
| def get_result(cache_id): | |
| if cache_id not in result_cache: | |
| return None | |
| if datetime.now() > result_cache[cache_id]['expiry']: | |
| del result_cache[cache_id] | |
| return None | |
| return result_cache[cache_id]['data'] |