Skip to content

Commit 38d1ff8

Browse files
Jan Adamsclaude
andcommitted
Fix review findings: extract shared traversal method, clarify docs
- Extract shared invalidateWithDependencies() from onUpdate/onDelete - Clarify doc/2 that enabled: false is mutually exclusive with other options - Add note to doc/3 that dependent element types must also be enabled in the main elements config for invalidation to take effect Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 2512374 commit 38d1ff8

3 files changed

Lines changed: 26 additions & 18 deletions

File tree

doc/2-configuration.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,30 @@ neusta_pimcore_http_cache:
1212
archive: false
1313
unknown: false
1414

15-
# Invalidate dependent elements when an asset changes (disabled by default)
15+
# Invalidate dependent elements when an asset changes (disabled by default).
16+
# Note: a dependent element type must also be enabled above for invalidation to take effect.
1617
invalidate_dependencies:
1718
enabled: true
1819
types:
1920
objects: true
2021
documents: true
2122

22-
# Unless you disable assets completely
23+
# Or disable assets completely (mutually exclusive with the options above)
2324
enabled: false
2425

2526
documents:
2627
# By default, every type except "email", "folder" and "hardlink" is enabled
2728
types:
2829
link: false
2930

30-
# Invalidate dependent elements when a document changes (disabled by default)
31+
# Invalidate dependent elements when a document changes (disabled by default).
32+
# Note: a dependent element type must also be enabled above for invalidation to take effect.
3133
invalidate_dependencies:
3234
enabled: true
3335
types:
3436
objects: true
3537

36-
# Unless you disable documents completely
38+
# Or disable documents completely (mutually exclusive with the options above)
3739
enabled: false
3840

3941
objects:
@@ -45,15 +47,16 @@ neusta_pimcore_http_cache:
4547
classes:
4648
MyDataObjectClass: false
4749

48-
# Invalidate dependent elements when an object changes (disabled by default)
50+
# Invalidate dependent elements when an object changes (disabled by default).
51+
# Note: a dependent element type must also be enabled above for invalidation to take effect.
4952
invalidate_dependencies:
5053
enabled: true
5154
types:
5255
objects: true
5356
documents: true
5457
assets: true
5558

56-
# Unless you disable data objects completely
59+
# Or disable data objects completely (mutually exclusive with the options above)
5760
enabled: false
5861

5962
# Enable/disable cache handling for custom cache types

doc/3-pimcore-elements.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,12 @@ Dependent element invalidation — traversing Pimcore's dependency graph to also
9292
9393
The dependency graph is one level deep: only elements that directly reference the changed element are invalidated, not transitive dependencies.
9494
95+
> **Note:** For a dependent element type to actually be invalidated, it must also be enabled in the main `elements` configuration. For example, setting `objects.invalidate_dependencies.types.documents: true` has no effect if `documents` is disabled — the cache tag will be silently dropped.
96+
9597
### Enable dependent invalidation for objects
9698

97-
The most common use case is invalidating documents and other objects that reference a changed data object:
99+
The most common use case is invalidating documents and other objects that reference a changed data object.
100+
The listed dependent types (`documents`, `objects`) must also be enabled in the `elements` configuration:
98101

99102
```yaml
100103
neusta_pimcore_http_cache:
@@ -106,11 +109,13 @@ neusta_pimcore_http_cache:
106109
documents: true # invalidate documents that reference the object
107110
objects: true # invalidate objects that reference the object
108111
assets: false # leave assets out (default)
112+
documents: true # must be enabled for document invalidation to take effect
109113
```
110114

111115
### Enable dependent invalidation for assets
112116

113-
If an asset (e.g. an image) is referenced by objects or documents, those can be invalidated when the asset changes:
117+
If an asset (e.g. an image) is referenced by objects or documents, those can be invalidated when the asset changes.
118+
The listed dependent types must also be enabled in the `elements` configuration:
114119

115120
```yaml
116121
neusta_pimcore_http_cache:
@@ -121,11 +126,14 @@ neusta_pimcore_http_cache:
121126
types:
122127
objects: true # invalidate objects that reference the asset
123128
documents: true # invalidate documents that reference the asset
129+
objects: true # must be enabled for object invalidation to take effect
130+
documents: true # must be enabled for document invalidation to take effect
124131
```
125132

126133
### Enable dependent invalidation for documents
127134

128-
If a document is referenced by other elements (e.g. an object with a document relation field), those elements can be invalidated when the document changes:
135+
If a document is referenced by other elements (e.g. an object with a document relation field), those elements can be invalidated when the document changes.
136+
The listed dependent types must also be enabled in the `elements` configuration:
129137

130138
```yaml
131139
neusta_pimcore_http_cache:
@@ -135,4 +143,5 @@ neusta_pimcore_http_cache:
135143
enabled: true
136144
types:
137145
objects: true # invalidate objects that reference the document
146+
objects: true # must be enabled for object invalidation to take effect
138147
```

src/Element/InvalidateElementListener.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,16 @@ public function onUpdate(ElementEventInterface $event): void
2525
return;
2626
}
2727

28-
$element = $event->getElement();
29-
30-
$this->invalidateElement($element);
31-
32-
$type = ElementType::tryFrom($element->getType());
33-
if ($type !== null && $this->isDependencyTraversalEnabled($type)) {
34-
$this->invalidateDependencies($element->getDependencies(), $type);
35-
}
28+
$this->invalidateWithDependencies($event->getElement());
3629
}
3730

3831
public function onDelete(ElementEventInterface $event): void
3932
{
40-
$element = $event->getElement();
33+
$this->invalidateWithDependencies($event->getElement());
34+
}
4135

36+
private function invalidateWithDependencies(ElementInterface $element): void
37+
{
4238
$this->invalidateElement($element);
4339

4440
$type = ElementType::tryFrom($element->getType());

0 commit comments

Comments
 (0)