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