From 6e6098b03af7335945773e742752af864c72c078 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sun, 7 Jan 2024 22:46:52 +0100 Subject: [PATCH] Fix faulty cache --- scanner/scanner/cache.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scanner/scanner/cache.py b/scanner/scanner/cache.py index b21a9851..0f02447d 100644 --- a/scanner/scanner/cache.py +++ b/scanner/scanner/cache.py @@ -5,7 +5,7 @@ from typing import Any, Optional, Tuple type Cache = dict[Any, Tuple[Optional[asyncio.Event], Optional[datetime], Any]] -def cache(ttl: timedelta, cache: Cache={}, typed=False): +def cache(ttl: timedelta, cache: Optional[Cache] = None, typed=False): """ A cache decorator for async methods. If the same method is called twice with the same args, the underlying method will only be called once and the first @@ -17,6 +17,9 @@ def cache(ttl: timedelta, cache: Cache={}, typed=False): """ + if cache is None: + cache = {} + def wrap(f): @wraps(f) async def wrapper(*args, **kwargs):