add custom cache backend for deleting many keys with a pattern

This commit is contained in:
sadnub 2022-04-10 22:42:10 -04:00
parent 2fe0b5b90d
commit 5aa7b5a337
2 changed files with 11 additions and 1 deletions

View File

@ -0,0 +1,10 @@
from django.core.cache.backends.redis import RedisCache
from typing import Optional
class TacticalRedisCache(RedisCache):
def delete_many_pattern(self, pattern: str, version: Optional[int] = None) -> None:
keys = self._cache.get_client().keys(f":{version if version else 1}:{pattern}")
if keys:
self._cache.delete_many(keys)

View File

@ -151,7 +151,7 @@ CHANNEL_LAYERS = {
CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.redis.RedisCache",
"BACKEND": "tacticalrmm.cache.TacticalRedisCache",
"LOCATION": f"redis://{REDIS_HOST}:6379",
"OPTIONS": {
"parser_class": "redis.connection.HiredisParser",