Skip to content

Commit 8a2542d

Browse files
committed
fix: change Cache-Control from max-age to no-cache for proper ETag validation
Root cause identified from network logs: - Browser was serving from disk cache without checking server - max-age=300 allowed browser to cache for 5 minutes without revalidation - Even with must-revalidate, browser only checks AFTER max-age expires - This caused stale data to be served from disk cache Solution: - Changed to: Cache-Control: private, no-cache, must-revalidate - no-cache forces browser to revalidate with server on EVERY request - Browser can still cache, but must check ETag first - If ETag matches, server returns 304 (fast, no body) - If ETag differs, server returns 200 with fresh data This ensures immediate cache invalidation when user data changes while still benefiting from ETag-based 304 responses.
1 parent 744f0da commit 8a2542d

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

‎src/Http/Controllers/Internal/v1/UserController.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public function current(Request $request)
197197
return response()->json(['user' => $cachedData])
198198
->setEtag($etag, true) // Use weak ETag for compression compatibility
199199
->setLastModified($user->updated_at)
200-
->header('Cache-Control', 'private, max-age=' . UserCacheService::getBrowserCacheTTL() . ', must-revalidate')
200+
->header('Cache-Control', 'private, no-cache, must-revalidate')
201201
->header('X-Cache-Hit', 'true');
202202
}
203203

@@ -216,7 +216,7 @@ public function current(Request $request)
216216
return response()->json(['user' => $userArray])
217217
->setEtag($etag, true) // Use weak ETag for compression compatibility
218218
->setLastModified($user->updated_at)
219-
->header('Cache-Control', 'private, max-age=' . UserCacheService::getBrowserCacheTTL() . ', must-revalidate')
219+
->header('Cache-Control', 'private, no-cache, must-revalidate')
220220
->header('X-Cache-Hit', 'false');
221221
}
222222

0 commit comments

Comments
 (0)