After logging in, the page is stored in a shared cache, and how should the private and non-cacheable headers in the cache header be written.
The page logged in is stored in a shared cache, and the problem is usually that the cache header is not written completely. According to MDN's definition, no-store means that any type of cache (private or shared) should not store the response; private means that the response can only be stored in private cache, that is, the browser's local cache. The difference between the two is not 'how long the cache is', but 'who is allowed to store'.'Pages with login status only write expiration time without writing ownership, and the shared cache may reuse that response for other users later.'
Who are the two types of caches?
Private cache is located on the user's side, typically in the browser's local cache, naturally isolated by users, and personalized content stored there usually does not constitute a leak.
Shared cache is located between the source site and the client, such as reverse proxy and CDN nodes. The MDN description is clear: it stores one response and resues it for multiple users. This is the source of risk - shared cache does not understand the login state; it only judges whether it is the same request based on the cache key.
There is a type that is often overlooked: the response cache within the application and the staticized products of the page. Their nature is between the two, depending on whether the generation time includes the user identity. Any cache that knows the current user at the time of generation and no longer distinguishes between users at the time of output should be treated as shared cache.
The meanings of 'not stored' and 'private' are distinct.
The applicable boundaries of the two should be clarified; getting it wrong is more麻烦 than not writing it at all.
| directive | semantics | Applicable objects | Consequences of misuse |
|---|---|---|---|
| no-store | No cache may store this response | Pages containing credentials, transactions, and personal data | With it, performance optimization is completely out of the question |
| private | Store privately | Pages that vary per person but are not sensitive | If the downstream still uses strong caching, it is equivalent to not being effective |
| Public + Expiration Time | Allow shared caching | Public content unrelated to identity | Personalized page errors will cause conflicts for users |
The order of choice is recommended to ask this way: Is there any information that belongs only to the current user in this response? If there is and it cannot be tolerated being read by others, use no-store. If the content varies from person to person but is not very sensitive, and caching can bring obvious benefits, use private. If it is unrelated to identity, it can enter the shared cache.
A common misconception is that 'private' will make the CDN not cache. A more accurate statement is that 'private' is a request for shared caches not to store it, but some intermediate layer behaviors do not completely adhere to this semantics. Therefore, 'no-store' is a more deterministic way of writing for truly sensitive responses.
Why is the member grouping page more likely to have problems?
The system supports user management and VIP groups, and can set access permissions for different user groups. Once this layered capability meets caching, it will form a typical page problem: The same address returns different content due to different user groups of the logged-in user, but this difference is not reflected in the cache key.
Three types of pages are most likely to be overlooked. The first is the member area entrance displayed after login, where different groups see different content; the second is the pages related to price, ordering, and orders, where permissions determine the visible range; the third is the pages for downloading or attachments, where permission verification is at the application layer, and once the response enters the shared cache, subsequent visits no longer trigger verification.
The third type is particularly dangerous: it gives people the illusion that 'I have done permission judgment in my program, so it is safe'. But the cache skips the program, and the permission judgment is not executed at all.
The standard for judgment should be whether the response is different for each person, not whether the page is important. Any response that has read the user's identity, group, or permission during rendering is automatically excluded from the shared cache, and sub-resources unrelated to identity can be opened separately as needed.
Side effects on reverse proxy and acceleration nodes
Adding another layer of cache on the link adds another risk, because the rules are scattered in two places: the application writes the response header, and the intermediate layer decides whether to follow its own strategy. When deploying the site, if there are both reverse proxy and acceleration nodes at the same time, these two layers should be checked together, and simply adjusting the application side is often not enough.
To verify four things. First, does the intermediate layer have a mandatory caching strategy. Some configurations will override upstream instructions, making the application side useless. Second, when the cache is hit, is the response header rewritten. If the header information is lost after caching, the client cannot see that this content comes from the cache. Third, is the old response in the cache still there after logging out. The login state change does not automatically invalidate the objects in the shared cache. Fourth, whether the staticized products are classified by user directory. Writing the login page as a static file is the most difficult to find in the same category of problems.
Three-step self-check
Step 1, access the same address with two different accounts to compare whether the response is really different. If the second visit gets the content of the first visit, it means that a shared cache that should not have been hit has been hit.
Step 2, look at the ownership statement and cache identifier in the response header to confirm which layer the response has been stored at. Responses missing the statement should be supplemented, and login state responses with cache hit traces should be handled immediately.
Step 3, check the logout login path. Reliable implementation should make the jump address after login not enter the shared cache, rather than relying on the client-side cleanup.
Common questions
Is it okay to add no-store to the entire site?Technically feasible, but it will sacrifice the caching benefits of public content, with the site load increasing significantly. It should be differentiated by response type rather than a global cut-off.
Is it enough just to add it to the login interface?Not enough. The problem lies in the page response rendered in the logged-in state, the interface is only part of it.
Will the private on CDN take effect?The behaviors of different implementations are not completely consistent, and sensitive responses should use no-store more reliably. It should be verified on a real node before going online rather than depending on documentation descriptions.
How can staticization be made safe?Pages unrelated to identity should be staticized; member-related content should be dynamically rendered based on permissions, or the differences should be converged into small areas that are not cached.
How to determine if there are any residual historical responses?Observe whether old content can still be accessed after logging out, or check the existence time of objects in the cache layer. When residuals are found, close the cache of the path first, and then investigate the generation logic.