fix: cache proxied channel logos as immutable responses - #834
Open
rahul-singh-solanki wants to merge 1 commit into
Open
rahul-singh-solanki wants to merge 1 commit into
rahul-singh-solanki wants to merge 1 commit into
Conversation
Avoid refetching the same Jio CDN PNG on every grid refresh, and advertise long-lived Cache-Control so browsers can skip the round trip. Co-authored-by: Cursor <cursoragent@cursor.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Channel logos are proxied through
/jtvimage/:file, but every page load re-fetched the same PNG from Jio's CDN because the response carried no caching hints. On a grid of ~1000 channels that is a large number of avoidable upstream requests on each visit. This PR keeps successful logo responses in process and marks them immutable for the browser, so repeat views cost nothing upstream.Changes
internal/handlers/handlers.gochannelImageCache(sync.Map) pluscachedChannelImage;ImageHandlernow serves cached bytes, stores successful proxy responses, and setsCache-Control: public, max-age=31536000, immutableinternal/handlers/handlers_test.goTestImageHandlerplaceholder withTestImageHandlerServesCachedLogo, which asserts the cached body, status,Cache-Control, andContent-Typewithout contacting upstreamKey Implementation Details
append([]byte(nil), ...)) before storing, because the fasthttp response buffer is pooled and reused after the handler returns.:fileparam short-circuits with 400 instead of building an upstream URL.sync.Mapcaches in this file. Logos are static assets, so no TTL or invalidation is introduced.Screenshots
N/A — no UI changes.
Test Areas
Cache-Control: public, max-age=31536000, immutable/jtvimage/with an empty file param returns 400 rather than hitting upstream