Plex: fix collision in cache keys (#2638)
authoranatosun <33899455+anatosun@users.noreply.github.com>
Wed, 26 Nov 2025 23:44:01 +0000 (00:44 +0100)
committerGitHub <noreply@github.com>
Wed, 26 Nov 2025 23:44:01 +0000 (00:44 +0100)
music_assistant/providers/plex/__init__.py
music_assistant/providers/plex/helpers.py

index 21bca99360c9e1b9599a4891ae7183121415e7c3..3a9bc17c5e7da556090d30448059bef8335733ba 100644 (file)
@@ -126,7 +126,7 @@ async def setup(
 
 async def get_config_entries(  # noqa: PLR0915
     mass: MusicAssistant,
-    instance_id: str | None = None,  # noqa: ARG001
+    instance_id: str | None = None,
     action: str | None = None,
     values: dict[str, ConfigValueType] | None = None,
 ) -> tuple[ConfigEntry, ...]:
@@ -276,6 +276,7 @@ async def get_config_entries(  # noqa: PLR0915
                     server_http_ip,
                     server_http_port,
                     server_http_verify_cert,
+                    instance_id,
                 )
             ):
                 msg = "Unable to retrieve Servers and/or Music Libraries"
index 0bd1645a9239efd3451bcfad3419a85e920cb226..665026e1e1b6c9c32396fc1fe0036c82bc1d7ae1 100644 (file)
@@ -22,11 +22,20 @@ async def get_libraries(
     local_server_ip: str,
     local_server_port: str,
     local_server_verify_cert: bool,
+    instance_id: str | None = None,
 ) -> list[str]:
     """
     Get all music libraries for all plex servers.
 
-    Returns a dict of Library names in format {'servername / library name':'baseurl'}
+    Returns a list of Library names in format ['servername / library name', ...]
+
+    :param mass: MusicAssistant instance.
+    :param auth_token: Authentication token for Plex server.
+    :param local_server_ssl: Whether to use SSL/HTTPS.
+    :param local_server_ip: IP address of the Plex server.
+    :param local_server_port: Port of the Plex server.
+    :param local_server_verify_cert: Whether to verify SSL certificate.
+    :param instance_id: Provider instance ID to use for cache isolation.
     """
     cache_key = "plex_libraries"
 
@@ -54,12 +63,20 @@ async def get_libraries(
             all_libraries.append(f"{plex_server.friendlyName} / {media_section.title}")
         return all_libraries
 
-    if cache := await mass.cache.get(cache_key, checksum=auth_token):
+    if cache := await mass.cache.get(
+        cache_key, checksum=auth_token, provider=instance_id or local_server_ip
+    ):
         return cast("list[str]", cache)
 
     result = await asyncio.to_thread(_get_libraries)
     # use short expiration for in-memory cache
-    await mass.cache.set(cache_key, result, checksum=auth_token, expiration=3600)
+    await mass.cache.set(
+        cache_key,
+        result,
+        checksum=auth_token,
+        expiration=3600,
+        provider=instance_id or "default",
+    )
     return result