EnkaNetwork.py/enkanetwork/cache.py

17 lines
373 B
Python
Raw Normal View History

2022-08-02 17:37:24 +00:00
import json
from cachetools import TTLCache
__all__ = ('Cache',)
2022-08-02 17:40:30 +00:00
2022-08-02 17:37:24 +00:00
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
2022-08-02 17:40:30 +00:00
async def set(self, key, value):
2022-08-02 17:40:30 +00:00
self.cache[key] = json.dumps(value)