mirror of
https://github.com/hay-kot/mealie.git
synced 2025-08-22 06:23:34 -07:00
Fix type hints
This commit is contained in:
parent
13828b2701
commit
557d3d1da2
1 changed files with 8 additions and 7 deletions
|
@ -1,10 +1,11 @@
|
|||
import time
|
||||
from typing import Any
|
||||
|
||||
|
||||
class AuthCache:
|
||||
def __init__(self, threshold: int = 500, default_timeout: int = 300):
|
||||
def __init__(self, threshold: int = 500, default_timeout: float = 300):
|
||||
self.default_timeout = default_timeout
|
||||
self._cache = {}
|
||||
self._cache: dict[str, tuple[float, Any]] = {}
|
||||
self.clear = self._cache.clear
|
||||
self._threshold = threshold
|
||||
|
||||
|
@ -18,14 +19,14 @@ class AuthCache:
|
|||
for key in toremove:
|
||||
self._cache.pop(key, None)
|
||||
|
||||
def _normalize_timeout(self, timeout: int):
|
||||
def _normalize_timeout(self, timeout: float | None) -> float:
|
||||
if timeout is None:
|
||||
timeout = self.default_timeout
|
||||
if timeout > 0:
|
||||
timeout = time.time() + timeout
|
||||
return timeout
|
||||
|
||||
async def get(self, key: str):
|
||||
async def get(self, key: str) -> Any:
|
||||
try:
|
||||
expires, value = self._cache[key]
|
||||
if expires == 0 or expires > time.time():
|
||||
|
@ -33,16 +34,16 @@ class AuthCache:
|
|||
except KeyError:
|
||||
return None
|
||||
|
||||
async def set(self, key: str, value: any, timeout: int = None):
|
||||
async def set(self, key: str, value: Any, timeout: float | None = None) -> bool:
|
||||
expires = self._normalize_timeout(timeout)
|
||||
self._prune()
|
||||
self._cache[key] = (expires, value)
|
||||
return True
|
||||
|
||||
async def delete(self, key: str):
|
||||
async def delete(self, key: str) -> bool:
|
||||
return self._cache.pop(key, None) is not None
|
||||
|
||||
async def has(self, key: str):
|
||||
async def has(self, key: str) -> bool:
|
||||
try:
|
||||
expires, value = self._cache[key]
|
||||
return expires == 0 or expires > time.time()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue