Problem/Motivation

@dawehner in #2335661-154: Outbound path & route processors must specify cacheability metadata:

+++ b/core/lib/Drupal/Core/Cache/SiteCacheContext.php
@@ -0,0 +1,36 @@
+ * @file
+ * Contains \Drupal\Core\Cache\SiteCacheContext.
+ */

OH holy moly, this should really be in a subnamespace, given how many we have. Is that something which is still doable? \Drupal\Core\Cache\Contexts maybe?

Proposed resolution

Move it.

Remaining tasks

None.

API changes

\Drupal\Core\Cache\CacheContextInterface and \Drupal\Core\Cache\CacheContextsManager end up one level deeper.

User interface changes

None.

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Task because it's an improvement, not a bug, nor a new feature.
Prioritized changes This is a followup for a recent critical issue: #2335661: Outbound path & route processors must specify cacheability metadata. While the namespace itself is not new, the interface is new as of #2428563: Introduce parameter-dependent cache contexts and having loads of different cache context is even more recent.
Disruption
  • Slightly disruptive for core/contributed and custom modules because an interface and a plugin manager's location have changed, which requires small updates to classes implementing that interface, and services that have that manager injected.
  • @berdir checked did not find any implementations in modules for his site.
  • @catch pointed out that it will also be rare for contrib to need to implement its own cache contexts (modules like OG and Domain might need to, but otherwise not many). So he suggested the impact was probably greater than the disruption from this.

Comments

catch’s picture

Good idea.

mitalimehta’s picture

Assigned: Unassigned » mitalimehta
wim leers’s picture

Thanks for taking this on, @mitalimehta!

mitalimehta’s picture

DrupalCon LA 2015

mitalimehta’s picture

Status: Active » Needs review
StatusFileSize
new80.79 KB

First Patch for this issue with the Changes to Cache Contexts.

At DrupalCon LA 2015 Sprints

Status: Needs review » Needs work

The last submitted patch, 5: Rename_Cache_Contexts-2483781-5.patch, failed testing.

borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new1.25 KB
new82.05 KB

2 files that used a cache context but didn't have the new namespace in their use statements.

Status: Needs review » Needs work

The last submitted patch, 7: move_cache_contexts-2483781-7.patch, failed testing.

borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new637 bytes
new1.88 KB
new82.67 KB

Looks like I forgot one.

Status: Needs review » Needs work

The last submitted patch, 9: move_cache_contexts-2483781-9.patch, failed testing.

borisson_’s picture

Status: Needs work » Needs review
StatusFileSize
new637 bytes
new2.69 KB
new83.48 KB

The remaining fatal errors seem to work locally, hopefully testbot agrees.

Status: Needs review » Needs work

The last submitted patch, 11: move_cache_contexts-2483781-11.patch, failed testing.

borisson_’s picture

I can't seem to reproduce the current errors locally when running tests.

rbayliss’s picture

Status: Needs work » Needs review
StatusFileSize
new89.01 KB
new6.13 KB

Looks like some mocked objects were missed in the conversion. Hopefully this fixes the failures.

wim leers’s picture

Status: Needs review » Needs work

Please reroll with git diff -M10%, that records these moves as … moves, instead of deletions/additions. Will make this patch a hundred times easier to review.

joshi.rohit100’s picture

Status: Needs work » Needs review
StatusFileSize
new37.48 KB

Rerolled

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

+1

wim leers’s picture

Not 100% sure we wanted to move CacheContextsManager as well, but I'm completely fine with it.

RTBC++

fabianx’s picture

+++ b/core/modules/views/tests/modules/views_test_data/src/Cache/ViewsTestCacheContext.php
@@ -7,7 +7,7 @@
diff --git a/core/tests/Drupal/Tests/Core/Cache/CacheContextsManagerTest.php b/core/tests/Drupal/Tests/Core/Cache/CacheContextsManagerTest.php

diff --git a/core/tests/Drupal/Tests/Core/Cache/CacheContextsManagerTest.php b/core/tests/Drupal/Tests/Core/Cache/CacheContextsManagerTest.php
index 859aee6..20f9f94 100644

index 859aee6..20f9f94 100644
--- a/core/tests/Drupal/Tests/Core/Cache/CacheContextsManagerTest.php

--- a/core/tests/Drupal/Tests/Core/Cache/CacheContextsManagerTest.php
+++ b/core/tests/Drupal/Tests/Core/Cache/CacheContextsManagerTest.php

If we move the CacheContextsManager, should we not move this one as well?

dawehner’s picture

If we move the CacheContextsManager, should we not move this one as well?

Yeah we better do.

wim leers’s picture

Status: Reviewed & tested by the community » Needs work
pounard’s picture

Why use plural into the "Context" namespace ? Just trolling but it feel very weird, Validator/Validate or Contraint namespaces are not plural if I remember correctly.

dawehner’s picture

Good point @pounard!

wim leers’s picture

Title: Move cache contexts classes from \Drupal\Core\Cache to \Drupal\Core\Cache\Contexts » Move cache contexts classes from \Drupal\Core\Cache to \Drupal\Core\Cache\Context
Issue tags: +Needs reroll

Good point. Let's go with singular for consistency.

pounard’s picture

Thanks, I'm +42 for this change, last time I was working on the Redis cache backend for D8, contextes where everywhere seriously polluting the overall cache design when I was navigating in the code, this change makes everything clearer.

catch’s picture

I'm wondering a bit why we don't make this \Drupal\Core\CacheContext - it's a completely separate API to the backends. But then we could also eventually do \Drupal\Core\Cache\Backend eventually. Do not mind very much, having everything at the same folder level is indeed confusing though.

fabianx’s picture

#26: Because \Drupal\Core\Cache\Cache deals also with cache contexts I think the current proposal is better.

It is part of the caching subsystem and yes indeed having a subfolder for backends would be good.

rbayliss’s picture

So just to recap the changes needed:

  • Move Drupal\Core\Cache\Contexts to Drupal\Core\Cache\Context
  • Move Drupal\Tests\Core\Cache\CacheContextsManagerTest to Drupal\Tests\Core\Cache\Context\CacheContextsManagerTest
fabianx’s picture

#28: Yes, that is correct.

rbayliss’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new37.61 KB
new39.09 KB

Here are the changes listed in #28

wim leers’s picture

Status: Needs review » Reviewed & tested by the community

Looks perfect! Thank you!

Note to committers: this will conflict very mildly with #1805054: Cache localized, access filtered, URL resolved, and rendered menu trees, so preferably this would only be committed after that one has landed.

xjm’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs beta evaluation, +Needs issue summary update

This issue is a normal task that introduces a BC break, and per https://www.drupal.org/core/beta-changes, we need to outline how it fits within the allowable Drupal 8 beta criteria. Can someone add Drupal 8 beta phase evaluation template to the issue summary. Also a bit clearer summary would be helpful since the issue it links to is very long. :)

wim leers’s picture

Issue summary: View changes
Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs beta evaluation, -Needs issue summary update

All done.

Note that the IS linked to a specific comment, not just an issue in general.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 30: move_cache_contexts-2483781-30.patch, failed testing.

wim leers’s picture

Issue tags: +Needs reroll
cilefen’s picture

Status: Needs work » Needs review
StatusFileSize
new35.9 KB
wim leers’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs reroll

Thanks!

catch’s picture

Assigned: mitalimehta » xjm

For the beta criteria I think this is an acceptable change because the class structure at the moment makes it quite difficult to know what's necessary to implement for what bits of the cache API - i.e. it's hard to see what's for backends/tags and what's for contexts, and this makes both clearer. Should have zero actual contrib impact since the API is very new and most modules won't need to interact with the classes/interfaces at all.

Assigning to xjm though in case I'm being overly generous.

fabianx’s picture

However we definitely need a change record and change record updates.

wim leers’s picture

Existing change records were all unaffected, as expected, because this only affects people writing their own cache contexts.

Unaffected:

CR created: https://www.drupal.org/node/2495707.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 36: move_cache_contexts-2483781-36.patch, failed testing.

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 36: move_cache_contexts-2483781-36.patch, failed testing.

wim leers’s picture

Issue tags: +Needs reroll

Darn!

cilefen’s picture

phpunit --debug -c core/
...
Starting test 'Drupal\Tests\system\Unit\Menu\MenuLinkTreeTest::testBuildCacheability with data set #0 ('Empty tree.', array(), array(array(array(), array(), -1)))'.
PHP Fatal error:  Call to undefined method Mock_CacheContextsManager_9df8c868::validateTokens() in /Library/WebServer/Documents/drupal8x/core/lib/Drupal/Core/Cache/Cache.php on line 40

Fatal error: Call to undefined method Mock_CacheContextsManager_9df8c868::validateTokens() in /Library/WebServer/Documents/drupal8x/core/lib/Drupal/Core/Cache/Cache.php on line 40

dawehner’s picture

@cilefen
Yeah, you need to update that class reference as well

cilefen’s picture

Status: Needs work » Needs review
StatusFileSize
new593 bytes
new36.61 KB
wim leers’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs reroll

Thank you!

xjm’s picture

Hrm. Unfortunately, while I can see why the reorganization of the classes would be a DX improvement, I don't really think this passes the beta criteria: https://www.drupal.org/core/beta-changes#flowchart

  1. It's not a feature request.
  2. It's not unfrozen or critical.
  3. It's not major nor a prioritized change (no bugfix, usability, accessibility, security, or performance impact).
  4. It doesn't really reduce fragility.

So even if the disruption is small, it seems to me we shouldn't make this change anymore at this point.

Not postponing just yet; going to check with @Wim Leers and @catch first.

dawehner’s picture

On the other hand we don't treat existing random classes as API, and which cache context is basically a random class.

xjm’s picture

Assigned: xjm » Unassigned
Issue summary: View changes
Status: Reviewed & tested by the community » Needs review
Issue tags: -Novice, -php-novice

So I talked about this more with @catch for the background information on this and why it's important. catch pointed out that this issue is a followup to a recent critical (#2335661: Outbound path & route processors must specify cacheability metadata) which is potentially a prioritized change. It's a bit borderline, because the namespace itself is not new, but the interface is new as of #2428563: Introduce parameter-dependent cache contexts and having loads of different cache context is even more recent.

So there is a case for it to go in. I've updated the beta evaluation clarifying why. (For the beta evaluations of the future: "DX" is not a prioritized beta change on its own; that's a priority for 8.1.x and 9.x depending on the BC. Cleaning up stuff that's introduced by fixing criticals, however is important and in scope, because the sooner the better once the critical lands, but without blocking it.) :D

One thing I'm not sure of is whether or not we should provide BC. See: https://www.drupal.org/core/beta-changes#bc

We could reduce the disruption of the change by making all the changers in this patch, but also retaining a \Drupal\Core\Cache\CacheContextInterface that is an empty extension of \Drupal\Core\Cache\Context\CacheContextInterface. I wasn't sure whether that would be better or worse than just moving the interface. We'd still move the child classes. Since those will typically be used via the core services provided for them, that'd mean the only disruption would be for subclasses of existing context which are even less likely to exist.

I see a case for just moving the interface since it's only three months old anyway. Setting NR for that. If others think that's best then just set it back to RTBC with that consensus.

Thanks everyone for your patience and your help explaining the change here in the issue and in IRC.

dawehner’s picture

Well yeah, having those kind of BC layers is not a bad idea. This would also allows us to put @deprecated on the class and then let people figure things out automatically.
But I agree with you, the interface is quite new, and the amount of contrib modules implementing that won't be that high. I vote for sanity.

berdir’s picture

But I agree with you, the interface is quite new, and the amount of contrib modules implementing that won't be that high.

Based on the /modules folder of d8status.md-systems.ch, which doesn't contain everything, but a lot (around 75 projects at the moment), that amount is currently 0 :)

There probably are some use cases around access and modules like organic groups, but those few modules haven't picked this concept/interface up yet.

From that perspective, moving it seems fine.

wim leers’s picture

Status: Needs review » Reviewed & tested by the community

But I agree with you, the interface is quite new, and the amount of contrib modules implementing that won't be that high. I vote for sanity.

[…] that amount is currently 0 :) […] From that perspective, moving it seems fine.

If others think that's best then just set it back to RTBC with that consensus.

xjm’s picture

Status: Reviewed & tested by the community » Fixed

Alright, in it goes then. Committed and pushed to 8.0.x. Thanks!

  • xjm committed 8305be4 on 8.0.x
    Issue #2483781 by borisson_, rbayliss, cilefen, mitalimehta, joshi....
xjm’s picture

I also published the CR.

dawehner’s picture

Awesome! Thank you for letting this in!!! This makes things sane ...

wim leers’s picture

Status: Fixed » Closed (fixed)

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