Skip to content

Instantly share code, notes, and snippets.

@Morreski
Morreski / timed_cache.py
Last active September 3, 2024 00:29
Python lru_cache with timeout
from datetime import datetime, timedelta
import functools
def timed_cache(**timedelta_kwargs):
def _wrapper(f):
update_delta = timedelta(**timedelta_kwargs)
next_update = datetime.utcnow() + update_delta
# Apply @lru_cache to f with no cache size limit