Cache Choices

Internally all data is ‘cached’ using an implementation which implements

In the standard package you have the following choices:

In order to use a cache other then the default one, simply pass in an instance of the cache you wish to use with the cache kwarg when initialising your AntiSpamHandler.

Alternately, use the AntiSpamHandler.set_cache method.

Once a cache is registered like so, there is nothing else you need to do. The package will simply use that caching mechanism.

Also note, AntiSpamHandler will call before any cache operations are undertaken.

Redis Cache

Here is an example, note RedisCache needs a extra argument.

 1import discord
 2from discord.ext import commands
 3from redis import asyncio as aioredis
 5from antispam import AntiSpamHandler
 6from antispam.caches.redis import RedisCache
 8bot = commands.Bot(command_prefix="!", intents=discord.Intents.all())
 9bot.handler = AntiSpamHandler(bot)
11redis = aioredis.from_url("redis://localhost")
12redis_cache: RedisCache = RedisCache(bot.handler, redis)

MongoDB Cache

Here is an example, note MongoCache needs a extra argument.

 1import discord
 2from discord.ext import commands
 4from antispam import AntiSpamHandler
 5from antispam.caches.mongo import MongoCache
 7bot = commands.Bot(command_prefix="!", intents=discord.Intents.all())
 8bot.handler = AntiSpamHandler(bot)
10my_cache = MongoCache(bot.handler, "Mongo connection url")