feat: two-layer in-memory caching for backend (closes #12) #14
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: shekhar/windows-iso-downloader#14
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "feat/caching-layer"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Reduces Microsoft API traffic from thousands/day to ~50–100/day, eliminating the 715-123130 rate-limit block under real traffic.
What's implemented
golang.org/x/sync/singleflightwraps all MS fetches — 500 concurrent cache misses → 1 API hitproduct_id— language lists are stableproduct_id:sku_idse(signed expiry) from CDN URL:(se - now) - 30min, falls back to 22hVerified locally
2026/05/18 22:45:50 eval warm: server-2025 -> 8 links cached
2026/05/18 22:45:50 MS fetch /skuinfo: product_id=3113 -> 38 languages
2026/05/18 22:45:50 /skuinfo: product_id=3113 -> fetched and cached
2026/05/18 22:45:50 /skuinfo: product_id=3113 -> cache hit
2026/05/18 22:45:50 /skuinfo: product_id=3113 -> cache hit
2026/05/18 22:45:52 /proxy: product_id=3113 sku_id=18480 -> fetched and cached until 2026-05-19T20:48:14
2026/05/18 22:45:52 /proxy: product_id=3113 sku_id=18480 -> cache hit
2026/05/18 22:46:07 /evallinks: product=server-2019 -> cache hit (8 links)
Test plan
cached until <timestamp>shows dynamic TTL (~22h from fetch time)Summary by CodeRabbit
Release Notes
New Features
Chores
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID:
28a1604d-fdea-4d32-8296-30f3122fbe04📥 Commits
Reviewing files that changed from the base of the PR and between
ddf96a873dandc6d8615cf1.⛔ Files ignored due to path filters (1)
backend/go.sumis excluded by!**/*.sum📒 Files selected for processing (2)
backend/go.modbackend/main.go📝 Walkthrough
Walkthrough
Refactored Microsoft API interactions in
backend/main.goto add multi-layer caching (SKU info, download links, negative cache, eval links), singleflight deduplication for concurrent requests, structured rate-limit error classification, jittered cache TTLs, and stale-on-failure serving. Dependency added:golang.org/x/syncfor singleflight.Changes
Microsoft Caching and Concurrency
backend/go.mod,backend/main.go(imports)golang.org/x/sync v0.20.0dependency; importedmath/randandgolang.org/x/sync/singleflightfor jitter and request deduplication.backend/main.go(cache globals, TTL constants)singleflight.Groupfor per-key deduplication of concurrent Microsoft fetches.backend/main.go(helpers, types, constants)jitter()for cache TTL variance,parseLinkExpiry()to extract expiry from Microsoft signed-URLseparameter,rateLimitErrortype to classify rate-limit signals (Type 9 / code715-123130), regex patterns for link/error extraction, and eval cache storage with TTL.backend/main.go(setupSession, fetchSKUInfo, fetchDownloadLinksFromMS, helpers)setupSession()to handle fingerprint-trigger requests and JS extraction; refactoredfetchSKUInfo()to return structured errors and raw bytes for caching; implementedfetchDownloadLinksFromMS()to map TooManyRequests and non-OK responses torateLimitError; added worker-secret header setter; refactored eval-links extraction with deduplication and language-first sorting.backend/main.go(/skuinfo, /proxy, /evallinks handlers)/skuinfochecks negative cache, then SKU cache, singleflights fetch, stores negative entries on rate-limit, caches success with jitter, returns raw JSON./proxychecks link cache, conditionally checks negative cache (only if no stale), singleflights per-product fetch, serves stale on failure, caches with dynamic expiry./evallinksserves cached results when fetch fails or yields zero links.backend/main.go(main function)main()to explicitly register/skuinfo,/proxy,/evallinks, and/healthhandlers; warmup and session cleanup logic retained.Estimated code review effort
🎯 4 (Complex) | ⏱️ ~50 minutes
Possibly related issues
Possibly related PRs
/skuinfoand/proxyMicrosoft-fetch paths inbackend/main.go;#7wraps requests via Cloudflare proxy/X-Worker-Secret header, while this PR adds caching, singleflight, and structured error handling around those same fetch flows.Poem
✨ Finishing Touches
📝 Generate docstrings
🧪 Generate unit tests (beta)
feat/caching-layerComment
@coderabbitai helpto get the list of available commands and usage tips.