Mercurial > libervia-backend
comparison sat/tools/common/async_utils.py @ 3936:ebe45ea2df3b
tools (common/async_utils): set default `maxsize` to 50 in `async_lru`
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 15 Oct 2022 20:37:00 +0200 |
parents | 9b45f0f168cf |
children |
comparison
equal
deleted
inserted
replaced
3935:80d29f55ba8b | 3936:ebe45ea2df3b |
---|---|
25 | 25 |
26 | 26 |
27 log = getLogger(__name__) | 27 log = getLogger(__name__) |
28 | 28 |
29 | 29 |
30 def async_lru(maxsize: Optional[int] = None) -> Callable: | 30 def async_lru(maxsize: Optional[int] = 50) -> Callable: |
31 """Decorator to cache async function results using LRU algorithm""" | 31 """Decorator to cache async function results using LRU algorithm |
32 | |
33 @param maxsize: maximum number of items to keep in cache. | |
34 None to have no limit | |
35 | |
36 """ | |
32 def decorator(func: Callable) -> Callable: | 37 def decorator(func: Callable) -> Callable: |
33 cache = OrderedDict() | 38 cache = OrderedDict() |
34 async def wrapper(*args) -> Awaitable: | 39 async def wrapper(*args) -> Awaitable: |
35 if args in cache: | 40 if args in cache: |
36 log.debug(f"using result in cache for {args}") | 41 log.debug(f"using result in cache for {args}") |