Skip to content

fix: cache proxied channel logos as immutable responses - #834

Open
rahul-singh-solanki wants to merge 1 commit into
JioTV-Go:developfrom
rahul-singh-solanki:fix/cache-channel-logos
Open

rahul-singh-solanki wants to merge 1 commit into
JioTV-Go:developfrom
rahul-singh-solanki:fix/cache-channel-logos

Conversation

@rahul-singh-solanki

@rahul-singh-solanki rahul-singh-solanki commented Sep 16, 2026

Copy link
Copy Markdown

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

File Change Type Description
internal/handlers/handlers.go Modified Add channelImageCache (sync.Map) plus cachedChannelImage; ImageHandler now serves cached bytes, stores successful proxy responses, and sets Cache-Control: public, max-age=31536000, immutable
internal/handlers/handlers_test.go Modified Replace the empty TestImageHandler placeholder with TestImageHandlerServesCachedLogo, which asserts the cached body, status, Cache-Control, and Content-Type without contacting upstream

Key Implementation Details

  • Only responses with status 200 and a non-empty body are cached, so upstream errors and empty replies are never memoised.
  • The body is copied (append([]byte(nil), ...)) before storing, because the fasthttp response buffer is pooled and reused after the handler returns.
  • An empty :file param short-circuits with 400 instead of building an upstream URL.
  • Cache lifetime is the process lifetime, matching the existing sync.Map caches in this file. Logos are static assets, so no TTL or invalidation is introduced.

Screenshots

N/A — no UI changes.

Test Areas

  • First request for a logo still proxies from Jio's CDN and renders correctly
  • Second request for the same logo is served from cache with Cache-Control: public, max-age=31536000, immutable
  • A failing/404 logo is not cached and retries upstream on the next request
  • /jtvimage/ with an empty file param returns 400 rather than hitting upstream
  • Channel grid still renders every logo after a hard refresh

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant