Mercurial > libervia-backend
diff libervia/backend/tools/common/async_utils.py @ 4270:0d7bb4df2343
Reformatted code base using black.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 19 Jun 2024 18:44:57 +0200 |
parents | 4b842c1fb686 |
children |
line wrap: on
line diff
--- a/libervia/backend/tools/common/async_utils.py Tue Jun 18 12:06:45 2024 +0200 +++ b/libervia/backend/tools/common/async_utils.py Wed Jun 19 18:44:57 2024 +0200 @@ -30,12 +30,14 @@ def async_lru(maxsize: Optional[int] = 50) -> Callable: """Decorator to cache async function results using LRU algorithm - @param maxsize: maximum number of items to keep in cache. - None to have no limit + @param maxsize: maximum number of items to keep in cache. + None to have no limit """ + def decorator(func: Callable) -> Callable: cache = OrderedDict() + async def wrapper(*args) -> Awaitable: if args in cache: log.debug(f"using result in cache for {args}") @@ -49,5 +51,7 @@ value = cache.popitem(False) log.debug(f"Removing LRU value: {value}") return result + return wrapper + return decorator