EnkaNetwork.py/enkanetwork/cache.py
Dee Dev 3ec03d9b06 Upgrade EnkaNetwork.py
- add http client
- update example

- add aenter, aexit for auto close client
2022-08-04 20:56:23 +07:00

17 lines
373 B
Python

import json
from cachetools import TTLCache
__all__ = ('Cache',)
class Cache:
def __init__(self, maxsize, ttl):
self.cache = TTLCache(maxsize, ttl)
async def get(self, key):
data = self.cache.get(key)
return json.loads(data) if data is not None else data
async def set(self, key, value):
self.cache[key] = json.dumps(value)