Fix faulty cache

This commit is contained in:
Zoe Roux 2024-01-07 22:46:52 +01:00
parent e1b555781c
commit 6e6098b03a

View File

@ -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):