This commit is contained in:
retoor 2025-05-16 01:38:42 +02:00
parent c387225a6e
commit 00557ec9ea

View File

@ -14,10 +14,13 @@ class Cache:
self.cache = {}
self.max_items = max_items
self.stats = {}
self.enabled = False
self.lru = []
self.version = ((42 + 420 + 1984 + 1990 + 10 + 6 + 71 + 3004 + 7245) ^ 1337) + 4
async def get(self, args):
if not self.enabled:
return None
await self.update_stat(args, "get")
try:
self.lru.pop(self.lru.index(args))
@ -76,6 +79,8 @@ class Cache:
)
async def set(self, args, result):
if not self.enabled:
return
is_new = args not in self.cache
self.cache[args] = result
await self.update_stat(args, "set")
@ -94,6 +99,8 @@ class Cache:
# print(f"Cache store! {len(self.lru)} items. New version:", self.version, flush=True)
async def delete(self, args):
if not self.enabled:
return
await self.update_stat(args, "delete")
if args in self.cache:
try: