use redis instead of cache

This commit is contained in:
lebaudantoine
2025-01-04 23:11:45 +01:00
parent 9830940d61
commit 3e3ca6a87b
+13 -4
View File
@@ -14,20 +14,29 @@ from django.conf import settings
from livekit.api import AccessToken, VideoGrants
from functools import lru_cache
import secrets
import string
from django.core.cache import cache
def generate_random_passphrase(length=26):
"""Generate a random passphrase using letters and digits"""
alphabet = string.ascii_letters + string.digits
return ''.join(secrets.choice(alphabet) for _ in range(length))
@lru_cache()
def get_cached_passphrase(room_slug):
def get_cached_passphrase(room_id):
"""Get or generate a cached passphrase for a room slug"""
return generate_random_passphrase()
# todo - discuss this hardcoded key prefix
passphrase = cache.get(f"room_passphrase:{room_id}")
if passphrase is None:
passphrase = generate_random_passphrase()
# Store in cache with a timeout (e.g., 24 hours = 86400 seconds)
cache.set(f"room_passphrase:{room_id}", passphrase, timeout=86400)
return passphrase
def generate_color(identity: str) -> str: