Files
vrobbler/vrobbler/apps/music/context_processors.py
Colin Powell 033239260f
All checks were successful
build / test (push) Successful in 1m57s
[perf] Add caching and lock protections
2026-06-19 13:37:30 -04:00

23 lines
645 B
Python

from django.core.cache import cache
from music.models import Artist, Album
CACHE_TTL = 300
def music_lists(request):
artist_list = cache.get("music_lists_artist_list")
if artist_list is None:
artist_list = list(Artist.objects.all().only("id", "name"))
cache.set("music_lists_artist_list", artist_list, CACHE_TTL)
album_list = cache.get("music_lists_album_list")
if album_list is None:
album_list = list(Album.objects.all().only("id", "name"))
cache.set("music_lists_album_list", album_list, CACHE_TTL)
return {
"artist_list": artist_list,
"album_list": album_list,
}