Problem/Motivation

This came up as a review point from #2784921-95: Add Workspaces experimental module.25:

+++ b/core/modules/workspace/src/WorkspaceCacheContext.php
@@ -0,0 +1,53 @@
+  /**
+   * {@inheritdoc}
+   */
+  public function getContext() {
+    return $this->workspaceManager->getActiveWorkspace();
+  }
...
+  public function getCacheableMetadata($type = NULL) {
+    return new CacheableMetadata();
+  }

Shouldn't the workspace negotiation inform the system how they determined this value? For example the session one depend on the current active session.

Proposed resolution

Discuss whether we need to do this and implement the solution.

Remaining tasks

TBD.

User interface changes

Nope.

API changes

Probably.

Data model changes

Nope.

CommentFileSizeAuthor
#9 interdiff-9.txt1.47 KBamateescu
#9 2934354-9.patch2.1 KBamateescu
#4 2934354.patch649 bytesamateescu

Comments

amateescu created an issue. See original summary.

fabianx’s picture

Yes, it should.

The reason why there is a getCacheableMetadata() method on CacheContexts is that those are living in a kind of hierarchy, e.g. user permissions is a good thing. You can cache that per user / session, but if you remove it you need to add the cache tags of the user.roles so if those change the permissions hash is updated.

e.g. think of it like when the cache context needs to be cached by something else. (e.g. in Varnish per url or per user session).

amateescu’s picture

Project: Workspace » Drupal core
Version: 8.x-2.x-dev » 8.6.x-dev
Component: Code » workspace.module
amateescu’s picture

Status: Active » Needs review
StatusFileSize
new649 bytes

@Fabianx, thanks for the detailed explanation. Given your last example and the fact that the active workspace will always end up in the user's session (e.g. workspaces do no make sense for anonymous users), I think this patch should be enough.

amateescu’s picture

Title: Consider whether workspace negotiators should expose cacheability metadata » Expose cacheability metadata in WorkspaceCacheContext
timmillwood’s picture

In the future we may add more active workspace negotiators, and contrib (such as Relaxed module) will also add these. Therefore, would it make sense for the negotiators to be able to set the cache context? In other words, should we add a getCacheContexts() method the negotiators?

fabianx’s picture

Status: Needs review » Reviewed & tested by the community

#6 It probably makes sense - yes.

The PR for now looks good to me however.

alexpott’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +Needs tests

I can't see a reason why we would have test coverage for this?

amateescu’s picture

Issue tags: -Needs tests
StatusFileSize
new2.1 KB
new1.47 KB

Added a couple of assertions to check that the cache context used by WorkspaceCacheContext is emitted properly.

amateescu’s picture

timmillwood’s picture

Status: Needs review » Reviewed & tested by the community

Looks good.

wim leers’s picture

Issue tags: +D8 cacheability

👌

plach’s picture

Saving credit

plach’s picture

Status: Reviewed & tested by the community » Fixed

Committed 7a61525 and pushed to 8.6.x. Thanks!

  • plach committed 7a61525 on 8.6.x
    Issue #2934354 by amateescu, Fabianx, alexpott: Expose cacheability...

Status: Fixed » Closed (fixed)

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

amateescu’s picture

Component: workspace.module » workspaces.module

Fix component following module rename.