Skip to content

Commit 67dd758

Browse files
committed
fix: collision in cache keys
1 parent 0c00c00 commit 67dd758

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

music_assistant/providers/plex/helpers.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ async def get_libraries(
2828
2929
Returns a dict of Library names in format {'servername / library name':'baseurl'}
3030
"""
31-
cache_key = "plex_libraries"
31+
# Include server IP and port in cache key to prevent collisions
32+
# between multiple Plex servers using the same MyPlex account token
33+
cache_key = f"plex_libraries_{local_server_ip}_{local_server_port}"
34+
old_cache_key = "plex_libraries"
3235

3336
def _get_libraries() -> list[str]:
3437
# create a listing of available music libraries on all servers
@@ -54,9 +57,18 @@ def _get_libraries() -> list[str]:
5457
all_libraries.append(f"{plex_server.friendlyName} / {media_section.title}")
5558
return all_libraries
5659

60+
# Check new cache key first
5761
if cache := await mass.cache.get(cache_key, checksum=auth_token):
5862
return cast("list[str]", cache)
5963

64+
# Migration: check old cache key and migrate to new format
65+
if old_cache := await mass.cache.get(old_cache_key, checksum=auth_token):
66+
# Migrate old cache to new key
67+
await mass.cache.set(cache_key, old_cache, checksum=auth_token, expiration=3600)
68+
# Delete old cache entry (note: delete doesn't support checksum parameter)
69+
await mass.cache.delete(old_cache_key)
70+
return cast("list[str]", old_cache)
71+
6072
result = await asyncio.to_thread(_get_libraries)
6173
# use short expiration for in-memory cache
6274
await mass.cache.set(cache_key, result, checksum=auth_token, expiration=3600)

0 commit comments

Comments
 (0)