Skip to content

Commit 2937806

Browse files
authored
Retrieve cache metadata from display. (#15)
* Retrieve cache metadata from display instead of view entity. * Suppress any url cache contexts emitted by views since they never apply here.
1 parent 772fc94 commit 2937806

9 files changed

Lines changed: 21 additions & 17 deletions

src/Plugin/Deriver/Fields/ViewDeriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function getDerivativeDefinitions($basePluginDefinition) {
4949
'display' => $displayId,
5050
'paged' => $this->isPaged($display),
5151
'arguments_info' => $info,
52-
] + $this->getCacheMetadataDefinition($view) + $basePluginDefinition;
52+
] + $this->getCacheMetadataDefinition($view, $display) + $basePluginDefinition;
5353
}
5454
}
5555

src/Plugin/Deriver/Fields/ViewResultCountDeriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function getDerivativeDefinitions($basePluginDefinition) {
3737
'parents' => [$display->getGraphQLResultName()],
3838
'view' => $viewId,
3939
'display' => $displayId,
40-
] + $this->getCacheMetadataDefinition($view) + $basePluginDefinition;
40+
] + $this->getCacheMetadataDefinition($view, $display) + $basePluginDefinition;
4141
}
4242
}
4343

src/Plugin/Deriver/Fields/ViewResultListDeriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function getDerivativeDefinitions($basePluginDefinition) {
3737
'view' => $viewId,
3838
'display' => $displayId,
3939
'uses_fields' => $style->usesFields(),
40-
] + $this->getCacheMetadataDefinition($view) + $basePluginDefinition;
40+
] + $this->getCacheMetadataDefinition($view, $display) + $basePluginDefinition;
4141
}
4242
}
4343

src/Plugin/Deriver/Fields/ViewRowFieldDeriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function getDerivativeDefinitions($basePluginDefinition) {
4242
'view' => $viewId,
4343
'display' => $displayId,
4444
'field' => $alias,
45-
] + $this->getCacheMetadataDefinition($view) + $basePluginDefinition;
45+
] + $this->getCacheMetadataDefinition($view, $display) + $basePluginDefinition;
4646
}
4747
}
4848
}

src/Plugin/Deriver/InputTypes/ViewContextualFilterInputDeriver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function getDerivativeDefinitions($basePluginDefinition) {
3030
$argumentsInfo = $this->getArgumentsInfo($display->getOption('arguments') ?: []);
3131
if (!empty($argumentsInfo)) {
3232
$id = implode('_', [
33-
$viewId, $displayId, 'view', 'contextual', 'filter', 'input'
33+
$viewId, $displayId, 'view', 'contextual', 'filter', 'input',
3434
]);
3535

3636
$this->derivatives[$id] = [
@@ -41,7 +41,7 @@ public function getDerivativeDefinitions($basePluginDefinition) {
4141
]),
4242
'view' => $viewId,
4343
'display' => $displayId,
44-
] + $this->getCacheMetadataDefinition($view) + $basePluginDefinition;
44+
] + $this->getCacheMetadataDefinition($view, $display) + $basePluginDefinition;
4545
}
4646
}
4747
}

src/Plugin/Deriver/InputTypes/ViewFilterInputDeriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function getDerivativeDefinitions($basePluginDefinition) {
6060
'fields' => $fields,
6161
'view' => $viewId,
6262
'display' => $displayId,
63-
] + $this->getCacheMetadataDefinition($view) + $basePluginDefinition;
63+
] + $this->getCacheMetadataDefinition($view, $display) + $basePluginDefinition;
6464
}
6565

6666
}

src/Plugin/Deriver/Types/ViewResultTypeDeriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function getDerivativeDefinitions($basePluginDefinition) {
3333
'name' => $display->getGraphQLResultName(),
3434
'view' => $viewId,
3535
'display' => $displayId,
36-
] + $this->getCacheMetadataDefinition($view) + $basePluginDefinition;
36+
] + $this->getCacheMetadataDefinition($view, $display) + $basePluginDefinition;
3737
}
3838
}
3939

src/Plugin/Deriver/Types/ViewRowTypeDeriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function getDerivativeDefinitions($basePluginDefinition) {
3939
'name' => $display->getGraphQLRowName(),
4040
'view' => $viewId,
4141
'display' => $displayId,
42-
] + $this->getCacheMetadataDefinition($view) + $basePluginDefinition;
42+
] + $this->getCacheMetadataDefinition($view, $display) + $basePluginDefinition;
4343
}
4444
}
4545

src/Plugin/Deriver/ViewDeriverBase.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -248,15 +248,19 @@ protected function getViewStyle(ViewEntityInterface $view, $displayId) {
248248
* @return array
249249
* The cache metadata definitions for the plugin definition.
250250
*/
251-
protected function getCacheMetadataDefinition(ViewEntityInterface $view) {
251+
protected function getCacheMetadataDefinition(ViewEntityInterface $view, DisplayPluginInterface $display) {
252+
$metadata = $display->getCacheMetadata()
253+
->addCacheTags($view->getCacheTags())
254+
->addCacheContexts($view->getCacheContexts())
255+
->mergeCacheMaxAge($view->getCacheMaxAge());
256+
252257
return [
253-
'schema_cache_tags' => $view->getCacheTags(),
254-
'schema_cache_max_age' => $view->getCacheMaxAge(),
255-
'response_cache_contexts' => array_merge($view->getCacheContexts(), [
256-
// TODO: check if they are really always there.
257-
'languages:language_interface',
258-
'languages:language_content',
259-
]),
258+
'schema_cache_tags' => $metadata->getCacheTags(),
259+
'schema_cache_max_age' => $metadata->getCacheMaxAge(),
260+
'response_cache_contexts' => array_filter($metadata->getCacheContexts(), function ($context) {
261+
// Don't emit the url cache contexts.
262+
return $context !== 'url' && strpos($context, 'url.') !== 0;
263+
}),
260264
];
261265
}
262266

0 commit comments

Comments
 (0)