cotienbot / src /cache.py
Anothervin1's picture
Create src/cache.py
12151a0 verified
raw
history blame contribute delete
782 Bytes
# File: src/cache.py
from cachetools import TTLCache
from config.settings import Settings
class Cache:
def __init__(self):
self.default_cache = TTLCache(maxsize=1000, ttl=Settings.CACHE_TTL)
self.gemini_cache = TTLCache(maxsize=500, ttl=Settings.CACHE_TTL)
self.lottery_cache = TTLCache(maxsize=100, ttl=Settings.CACHE_TTL)
def get(self, key, type="default"):
cache = (self.gemini_cache if type == "gemini" else
self.lottery_cache if type == "lottery" else self.default_cache)
return cache.get(key)
def set(self, key, value, type="default"):
cache = (self.gemini_cache if type == "gemini" else
self.lottery_cache if type == "lottery" else self.default_cache)
cache[key] = value