diff options
author | Zach White <skullydazed@gmail.com> | 2020-10-25 14:48:44 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-25 14:48:44 -0700 |
commit | 0c42f91f4ccf98a37f055afb777ed491da56335e (patch) | |
tree | 547344d80fe7bf75ff3f348eefbc19dbdd346a8a /lib/python/qmk/decorators.py | |
parent | 8ef82c466e73e555fd74107d4c57e678d7152ecc (diff) |
Generate api data on each push (#10609)
* add new qmk generate-api command, to generate a complete set of API data.
* Generate api data and push it to the keyboard repo
* fix typo
* Apply suggestions from code review
Co-authored-by: Joel Challis <git@zvecr.com>
* fixup api workflow
* remove file-changes-action
* use a more mainstream github action
* fix yaml error
* Apply suggestions from code review
Co-authored-by: Erovia <Erovia@users.noreply.github.com>
* more uniform date handling
* make flake8 happy
* Update lib/python/qmk/decorators.py
Co-authored-by: Erovia <Erovia@users.noreply.github.com>
Co-authored-by: Joel Challis <git@zvecr.com>
Co-authored-by: Erovia <Erovia@users.noreply.github.com>
Diffstat (limited to 'lib/python/qmk/decorators.py')
-rw-r--r-- | lib/python/qmk/decorators.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/python/qmk/decorators.py b/lib/python/qmk/decorators.py index f8f2facb1c..629402b095 100644 --- a/lib/python/qmk/decorators.py +++ b/lib/python/qmk/decorators.py @@ -2,6 +2,7 @@ """ import functools from pathlib import Path +from time import monotonic from milc import cli @@ -84,3 +85,38 @@ def automagic_keymap(func): return func(*args, **kwargs) return wrapper + + +def lru_cache(timeout=10, maxsize=128, typed=False): + """Least Recently Used Cache- cache the result of a function. + + Args: + + timeout + How many seconds to cache results for. + + maxsize + The maximum size of the cache in bytes + + typed + When `True` argument types will be taken into consideration, for example `3` and `3.0` will be treated as different keys. + """ + def wrapper_cache(func): + func = functools.lru_cache(maxsize=maxsize, typed=typed)(func) + func.expiration = monotonic() + timeout + + @functools.wraps(func) + def wrapped_func(*args, **kwargs): + if monotonic() >= func.expiration: + func.expiration = monotonic() + timeout + + func.cache_clear() + + return func(*args, **kwargs) + + wrapped_func.cache_info = func.cache_info + wrapped_func.cache_clear = func.cache_clear + + return wrapped_func + + return wrapper_cache |