Commit 628af17
authored
fix(api): disable caching for refresh=true stats requests (JhaSourav07#1981)
## Description
This PR fixes cache behavior for the `/api/stats` endpoint when the
`refresh=true` query parameter is used.
Previously, requests using `refresh=true` correctly bypassed the
internal GitHub cache, but the response itself still returned cacheable
headers. This allowed downstream caches (CDNs, proxies, or intermediary
layers) to potentially store and serve stale responses even after an
explicit refresh request.
### Changes Made
* Added refresh-aware cache handling for the stats endpoint.
* Return non-cacheable headers when `refresh=true` is present:
* `Cache-Control: no-store, no-cache, must-revalidate`
* `Pragma: no-cache`
* `Expires: 0`
* Preserved the existing caching strategy for normal requests.
* Added regression tests covering:
* Refresh requests returning non-cacheable headers.
* Refresh requests still returning valid stats data.
* Normal requests retaining existing cache behavior.
* Refactored header handling using a concrete `Headers` instance to
satisfy TypeScript type requirements and ensure production builds
succeed.
Fixes JhaSourav07#1966
---
## Pillar
🐛 Bug Fix
---
## Checklist
* [x] Linked this PR to an assigned issue
* [x] Kept changes scoped to the issue requirements
* [x] Added/updated tests where applicable
* [x] Verified formatting locally
* [x] Verified linting locally
* [x] Verified type checking locally
* [x] Verified tests locally
* [x] Verified production build locally
* [x] Reviewed the implementation before submission
---
## Validation
Successfully verified locally using:
```bash
npm run format:check
npm run lint
npm run typecheck
npm run test
npm run build
```
### Results
* Format check: Passed
* Lint: Passed (warnings only, no errors)
* TypeScript type check: Passed
* Test suite: Passed (1199/1199 tests)
* Production build: Passed
### Impact
This change ensures that users explicitly requesting fresh statistics
receive responses that cannot be cached by intermediate layers while
preserving the existing caching benefits and performance optimizations
for normal requests.2 files changed
Lines changed: 41 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
106 | 136 | | |
107 | 137 | | |
108 | 138 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
53 | 63 | | |
54 | 64 | | |
55 | 65 | | |
56 | 66 | | |
57 | 67 | | |
58 | 68 | | |
59 | 69 | | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
| 70 | + | |
66 | 71 | | |
67 | 72 | | |
68 | 73 | | |
| |||
0 commit comments