Skip to content

Instantly share code, notes, and snippets.

View EverythingSuckz's full-sized avatar
🦍
Learning :)

wrench EverythingSuckz

🦍
Learning :)
View GitHub Profile
@jmdacruz
jmdacruz / timed_cache.py
Last active July 26, 2022 13:40 — forked from Morreski/timed_cache.py
Python lru_cache with timeout
from datetime import datetime, timedelta
import functools
def timed_cache(**timedelta_kwargs):
def _wrapper(f):
maxsize = timedelta_kwargs.pop('maxsize', 128)
typed = timedelta_kwargs.pop('typed', False)
update_delta = timedelta(**timedelta_kwargs)
@Morreski
Morreski / timed_cache.py
Last active June 11, 2024 01:13
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