mirror of
https://github.com/SoPat712/allstarr.git
synced 2026-02-09 23:55:10 -05:00
feat: add 1-hour cache for playlist cover images
This commit is contained in:
@@ -1621,6 +1621,16 @@ public class JellyfinController : ControllerBase
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
// Check cache first (1 hour TTL for playlist images since they can change)
|
||||||
|
var cacheKey = $"playlist:image:{playlistId}";
|
||||||
|
var cachedImage = await _cache.GetAsync<byte[]>(cacheKey);
|
||||||
|
|
||||||
|
if (cachedImage != null)
|
||||||
|
{
|
||||||
|
_logger.LogDebug("Serving cached playlist image for {PlaylistId}", playlistId);
|
||||||
|
return File(cachedImage, "image/jpeg");
|
||||||
|
}
|
||||||
|
|
||||||
var (provider, externalId) = PlaylistIdHelper.ParsePlaylistId(playlistId);
|
var (provider, externalId) = PlaylistIdHelper.ParsePlaylistId(playlistId);
|
||||||
var playlist = await _metadataService.GetPlaylistAsync(provider, externalId);
|
var playlist = await _metadataService.GetPlaylistAsync(provider, externalId);
|
||||||
|
|
||||||
@@ -1637,6 +1647,11 @@ public class JellyfinController : ControllerBase
|
|||||||
|
|
||||||
var imageBytes = await response.Content.ReadAsByteArrayAsync();
|
var imageBytes = await response.Content.ReadAsByteArrayAsync();
|
||||||
var contentType = response.Content.Headers.ContentType?.ToString() ?? "image/jpeg";
|
var contentType = response.Content.Headers.ContentType?.ToString() ?? "image/jpeg";
|
||||||
|
|
||||||
|
// Cache for 1 hour (playlists can change, so don't cache too long)
|
||||||
|
await _cache.SetAsync(cacheKey, imageBytes, TimeSpan.FromHours(1));
|
||||||
|
_logger.LogDebug("Cached playlist image for {PlaylistId}", playlistId);
|
||||||
|
|
||||||
return File(imageBytes, contentType);
|
return File(imageBytes, contentType);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|||||||
@@ -559,6 +559,16 @@ public class SubsonicController : ControllerBase
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
// Check cache first (1 hour TTL for playlist images since they can change)
|
||||||
|
var cacheKey = $"playlist:image:{id}";
|
||||||
|
var cachedImage = await _cache.GetAsync<byte[]>(cacheKey);
|
||||||
|
|
||||||
|
if (cachedImage != null)
|
||||||
|
{
|
||||||
|
_logger.LogDebug("Serving cached playlist cover art for {Id}", id);
|
||||||
|
return File(cachedImage, "image/jpeg");
|
||||||
|
}
|
||||||
|
|
||||||
var (provider, externalId) = PlaylistIdHelper.ParsePlaylistId(id);
|
var (provider, externalId) = PlaylistIdHelper.ParsePlaylistId(id);
|
||||||
var playlist = await _metadataService.GetPlaylistAsync(provider, externalId);
|
var playlist = await _metadataService.GetPlaylistAsync(provider, externalId);
|
||||||
|
|
||||||
@@ -576,6 +586,11 @@ public class SubsonicController : ControllerBase
|
|||||||
|
|
||||||
var imageBytes = await imageResponse.Content.ReadAsByteArrayAsync();
|
var imageBytes = await imageResponse.Content.ReadAsByteArrayAsync();
|
||||||
var contentType = imageResponse.Content.Headers.ContentType?.ToString() ?? "image/jpeg";
|
var contentType = imageResponse.Content.Headers.ContentType?.ToString() ?? "image/jpeg";
|
||||||
|
|
||||||
|
// Cache for 1 hour (playlists can change, so don't cache too long)
|
||||||
|
await _cache.SetAsync(cacheKey, imageBytes, TimeSpan.FromHours(1));
|
||||||
|
_logger.LogDebug("Cached playlist cover art for {Id}", id);
|
||||||
|
|
||||||
return File(imageBytes, contentType);
|
return File(imageBytes, contentType);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|||||||
Reference in New Issue
Block a user