Created
January 31, 2022 10:01
-
-
Save kobus-v-schoor/4a19aad690f5d95131db352ecd992784 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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