Skip to content

cache TorBox CDN download URLs to reduce API call frequency#303

Open
mainLink0435 wants to merge 1 commit into
sirrobot01:mainfrom
mainLink0435:torbox-cdn-cache
Open

cache TorBox CDN download URLs to reduce API call frequency#303
mainLink0435 wants to merge 1 commit into
sirrobot01:mainfrom
mainLink0435:torbox-cdn-cache

Conversation

@mainLink0435
Copy link
Copy Markdown

@mainLink0435 mainLink0435 commented May 21, 2026

📌 Description

  • Caches TorBox CDN links for an amount of time to avoid calling the API every time and to help avoid API limits

Target Branch Check (IMPORTANT)

  • [ X] I confirm this PR is targeting the correct branch

Expected target:

  • beta (for features)

Changes Made

  • fetchDownloadLink was building a ?redirect=true URL and storing that in the link cache. Because the redirect URL hits the TorBox API on every stream request, the cache was effectively decorative — every file access still incurred a full API round-trip and counted against rate limits.
  • Removes redirect=true and instead resolves the real CDN URL at link-fetch time by decoding the JSON response. The CDN URL is then stored in the per-account link cache and reused for all stream requests until autoExpiresLinksAfter elapses.
  • Also adds an expiry check in account.GetDownloadLink: ExpiresAt was already being set by all providers but was never enforced - the cache would serve stale links indefinitely until restart. The check ensures expired entries are re-fetched rather than returned.

Testing

  • [X ] Tested locally

Steps:

  1. build dockerfile via gitea
  2. ran in place of official build
  3. additional debug logging confirmed CDN cache works as expected

Risks / Notes

  • the account.GetDownloadLink: ExpiresAt is actually being enforced across all providers.

Screenshots (if applicable)


Checklist

  • [X ] Code builds successfully
  • [ X] No console/log errors
  • [ X] Reviewed my own code
  • [ X] Target branch is correct

fetchDownloadLink was building a ?redirect=true URL and storing that in the link cache. Because the redirect URL hits the TorBox API on every stream request, the cache was effectively decorative — every file access still incurred a full API round-trip and counted against rate limits.

Removes redirect=true and instead resolves the real CDN URL at link-fetch time by decoding the JSON response. The CDN URL is then stored in the per-account link cache and reused for all stream requests until autoExpiresLinksAfter elapses.

Also adds an expiry check in account.GetDownloadLink: ExpiresAt was already being set by all providers but was never enforced — the cache would serve stale links indefinitely until restart. The check ensures expired entries are re-fetched rather than returned.
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