Update.
This commit is contained in:
parent
c387225a6e
commit
00557ec9ea
@ -14,10 +14,13 @@ class Cache:
|
|||||||
self.cache = {}
|
self.cache = {}
|
||||||
self.max_items = max_items
|
self.max_items = max_items
|
||||||
self.stats = {}
|
self.stats = {}
|
||||||
|
self.enabled = False
|
||||||
self.lru = []
|
self.lru = []
|
||||||
self.version = ((42 + 420 + 1984 + 1990 + 10 + 6 + 71 + 3004 + 7245) ^ 1337) + 4
|
self.version = ((42 + 420 + 1984 + 1990 + 10 + 6 + 71 + 3004 + 7245) ^ 1337) + 4
|
||||||
|
|
||||||
async def get(self, args):
|
async def get(self, args):
|
||||||
|
if not self.enabled:
|
||||||
|
return None
|
||||||
await self.update_stat(args, "get")
|
await self.update_stat(args, "get")
|
||||||
try:
|
try:
|
||||||
self.lru.pop(self.lru.index(args))
|
self.lru.pop(self.lru.index(args))
|
||||||
@ -76,6 +79,8 @@ class Cache:
|
|||||||
)
|
)
|
||||||
|
|
||||||
async def set(self, args, result):
|
async def set(self, args, result):
|
||||||
|
if not self.enabled:
|
||||||
|
return
|
||||||
is_new = args not in self.cache
|
is_new = args not in self.cache
|
||||||
self.cache[args] = result
|
self.cache[args] = result
|
||||||
await self.update_stat(args, "set")
|
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)
|
# print(f"Cache store! {len(self.lru)} items. New version:", self.version, flush=True)
|
||||||
|
|
||||||
async def delete(self, args):
|
async def delete(self, args):
|
||||||
|
if not self.enabled:
|
||||||
|
return
|
||||||
await self.update_stat(args, "delete")
|
await self.update_stat(args, "delete")
|
||||||
if args in self.cache:
|
if args in self.cache:
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user