🎨 Update code style in utils/enkanetwork.py

This commit is contained in:
洛水居室 2023-09-06 15:53:02 +08:00
parent f1de1c987d
commit b4ef81dae6
No known key found for this signature in database
GPG Key ID: C9DE87DA724B88FC

View File

@ -19,7 +19,19 @@ except ImportError:
if TYPE_CHECKING: if TYPE_CHECKING:
from redis import asyncio as aioredis from redis import asyncio as aioredis
__all__ = ("RedisCache",) __all__ = ("RedisCache", "StaticCache", "HTTPClient", "EnkaNetworkAPI")
class StaticCache(Cache):
def __init__(self, maxsize: int, ttl: int) -> None:
self.cache = TTLCache(maxsize, ttl)
async def get(self, key) -> Dict[str, Any]:
data = self.cache.get(key)
return jsonlib.loads(data) if data is not None else data
async def set(self, key, value) -> None:
self.cache[key] = jsonlib.dumps(value)
class RedisCache(Cache): class RedisCache(Cache):
@ -100,18 +112,6 @@ class HTTPClient(_HTTPClient):
return {"status": response.status_code, "content": response.content} return {"status": response.status_code, "content": response.content}
class StaticCache(Cache):
def __init__(self, maxsize: int, ttl: int) -> None:
self.cache = TTLCache(maxsize, ttl)
async def get(self, key) -> Dict[str, Any]:
data = self.cache.get(key)
return jsonlib.loads(data) if data is not None else data
async def set(self, key, value) -> None:
self.cache[key] = jsonlib.dumps(value)
class EnkaNetworkAPI(_EnkaNetworkAPI): class EnkaNetworkAPI(_EnkaNetworkAPI):
def __init__( def __init__(
self, self,