Skip to content

Instantly share code, notes, and snippets.

@kobus-v-schoor
Created January 31, 2022 10:01
Show Gist options
  • Save kobus-v-schoor/4a19aad690f5d95131db352ecd992784 to your computer and use it in GitHub Desktop.
Save kobus-v-schoor/4a19aad690f5d95131db352ecd992784 to your computer and use it in GitHub Desktop.
import time
from functools import lru_cache, wraps
def ttl_cache(ttl=600):
def outer(func):
@lru_cache
def inner(*args, ttl, **kwargs):
return func(*args, **kwargs)
@wraps(func)
def wrapper(*args, **kwargs):
return inner(*args, ttl=int(time.time() / ttl), **kwargs)
return wrapper
return outer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment