Problem/Motivation

Cache Contexts do bubble now, but there is no easy way to see what cache contexts are present on a page.

Proposed resolution

Similar to the X-Drupal-Cache-Tags add a X-Drupal-Cache-Contexts header to aid in debugging.

Remaining tasks

- Write patch

User interface changes

- None

API changes

- Output of a new header that will be very useful for debugging.

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Task, because its a simple task.
Issue priority Normal, because while important for debugging, it does not break anything to not have it.
Prioritized changes The main goal of this issue is to help with debugging our new cache context system.
Disruption Not disruptive due to nothing changing, just an addition of a HTTP header.

Comments

wim leers’s picture

Component: cache system » request processing system
Status: Active » Needs review
Issue tags: +DX (Developer Experience), +Needs tests
StatusFileSize
new1.19 KB

Initial patch. Testless.

wim leers’s picture

StatusFileSize
new2.04 KB
new2.05 KB

And cleaner/simpler version.

fabianx’s picture

Really nice, just needs some tests.

wim leers’s picture

Issue tags: -Needs tests
StatusFileSize
new5.57 KB
new3.58 KB

Done.

fabianx’s picture

Status: Needs review » Reviewed & tested by the community

What should I say:

- Code is simpler
- Tests are better
- Debugging is nicer

I guess I say: RTBC! :)

nielsvm’s picture

One of the awesome ideas this allows (indeed) is to let Varnish do this:

hash_data(req,url, req.X-Drupal-Cache-Contexts);

https://www.varnish-software.com/static/book/VCL_functions.html#vcl-vcl-...

+1;

fabianx’s picture

#7:

Yes, that is the plan too, but its not as simple as that, because the hash is for the original CID not the what comes in via the reply of the backend.

The trick is to have Drupal and Varnish negotiate a list of Cache Contexts that Varnish supports (e.g. by querying Drupal once and caching those not changing things per SESSION as the path /cache-contexts/user (so that it can be invalidated if something changes on that)).

Then with the restart functionality indeed this header can be used to differentiate the hash, based on the contents of the Cache Contexts. (resolved within Varnish itself).

wim leers’s picture

#7 & #8: Yes, those are nice side-effects, but that's not the actual goal of this issue. Let's keep that discussion for another issue :)

berdir’s picture

Just wondering, is it possible that a cache context could be exposing some kind of data that you wouldn't want to be visible?

wim leers’s picture

Title: Add a X-Drupal-Cache-Contexts header to aid in debugging » Add a X-Drupal-Cache-Contexts header to aid in debugging and testing

Another important use case for this: tests. Without this header, it's nigh impossible to check if a certain cache context is present on a page.


#10: I wondered the same back when I added X-Drupal-Cache-Tags, which has far more sensitive data (the *exact* things on the page) and it was deemed not problematic. Since this doesn't list the *exact* values for the cache contexts, but just the various cache contexts in play on a particular page (which anybody can find by grepping Drupal core/contrib), I don't see how this could ever amount to information disclosure.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 7eaa1b7 and pushed to 8.0.x. Thanks!

Thanks for adding the beta evaluation to the issue summary.

  • alexpott committed 7eaa1b7 on 8.0.x
    Issue #2445761 by Wim Leers: Add a X-Drupal-Cache-Contexts header to aid...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.