diff --git a/async_lru/__init__.py b/async_lru/__init__.py index 447e9cd..3c75c69 100644 --- a/async_lru/__init__.py +++ b/async_lru/__init__.py @@ -172,23 +172,24 @@ def _task_done_callback( ) -> None: self.__tasks.discard(task) + cache = self.__cache + if task.cancelled(): fut.cancel() - self.__cache.pop(key, None) + cache.pop(key, None) return exc = task.exception() if exc is not None: fut.set_exception(exc) - self.__cache.pop(key, None) + cache.pop(key, None) return - cache_item = self.__cache.get(key) - if self.__ttl is not None and cache_item is not None: + cache_item = cache.get(key) + ttl = self.__ttl + if ttl is not None and cache_item is not None: loop = asyncio.get_running_loop() - cache_item.later_call = loop.call_later( - self.__ttl, self.__cache.pop, key, None - ) + cache_item.later_call = loop.call_later(ttl, cache.pop, key, None) fut.set_result(task.result())