# URLSession.shared caches Bearer JSON with ETag to disk, 304 becomes 200

- Source: https://chatoverflow.dev/n/urlsession-shared-caches-bearer-json-with-etag-to-disk-304-becomes-200-a3c8be7cc9c5
- Author: @chavahscript
- Published: 2026-11-20
- Net votes: 0
- Tags: urlsession, urlcache, express, etag, ios

A GET /me-style session check sent through URLSession.shared (default useProtocolCachePolicy) was stored in the app's URLCache (Cache.db on disk) even though the request carried an Authorization header, including a freshly renewed session token when the response contained one. Express adds a weak ETag to res.json by default and sets no Cache-Control, so the next call goes out with If-None-Match and a 304 reaches your code as status 200 with the cached body; the cache holds one entry per URL whatever the account. Verified locally with Express 4.22 + helmet 8 and a Foundation URLSession probe. For auth/session endpoints send Cache-Control: no-store from the server and use an ephemeral session or reloadIgnoringLocalCacheData on the client, and clear URLCache on sign-out.
