aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar shtlrs <[email protected]>2023-07-10 19:36:53 +0100
committerGravatar shtlrs <[email protected]>2023-08-26 11:34:10 +0200
commit959e2ddcf74c7da5186b0d2ad86f0fb54e55cabe (patch)
tree928cca775b51df2215580f243567f33471dcbdb5
parentupdate all instances of send_to_paste_service (diff)
use bot-core caching util
-rw-r--r--bot/exts/info/pep.py2
-rw-r--r--bot/utils/caching.py42
2 files changed, 1 insertions, 43 deletions
diff --git a/bot/exts/info/pep.py b/bot/exts/info/pep.py
index 3854d02d5..08ccbddc5 100644
--- a/bot/exts/info/pep.py
+++ b/bot/exts/info/pep.py
@@ -4,11 +4,11 @@ from io import StringIO
from discord import Colour, Embed
from discord.ext.commands import Cog, Context, command
+from pydis_core.utils.caching import AsyncCache
from bot.bot import Bot
from bot.constants import Keys
from bot.log import get_logger
-from bot.utils.caching import AsyncCache
log = get_logger(__name__)
diff --git a/bot/utils/caching.py b/bot/utils/caching.py
deleted file mode 100644
index 2d0e077ec..000000000
--- a/bot/utils/caching.py
+++ /dev/null
@@ -1,42 +0,0 @@
-import functools
-from collections import OrderedDict
-from collections.abc import Callable
-from typing import Any
-
-
-class AsyncCache:
- """
- LRU cache implementation for coroutines.
-
- Once the cache exceeds the maximum size, keys are deleted in FIFO order.
-
- An offset may be optionally provided to be applied to the coroutine's arguments when creating the cache key.
- """
-
- def __init__(self, max_size: int = 128):
- self._cache = OrderedDict()
- self._max_size = max_size
-
- def __call__(self, arg_offset: int = 0) -> Callable:
- """Decorator for async cache."""
-
- def decorator(function: Callable) -> Callable:
- """Define the async cache decorator."""
-
- @functools.wraps(function)
- async def wrapper(*args) -> Any:
- """Decorator wrapper for the caching logic."""
- key = args[arg_offset:]
-
- if key not in self._cache:
- if len(self._cache) > self._max_size:
- self._cache.popitem(last=False)
-
- self._cache[key] = await function(*args)
- return self._cache[key]
- return wrapper
- return decorator
-
- def clear(self) -> None:
- """Clear cache instance."""
- self._cache.clear()