Oziris
August 1, 2020, 8:36am
1
Hi,
The doc says we can provide a list of page IDs to be ignored from the cache. I’m looking for the correct synthax to make the cache work on multiple pages inside these lines :
'cache' => [
'pages' => [
'active' => true,
'ignore' => function ($page) {
return $page->title()->value() === 'Do not cache me';
}
]
]
I tried many ways to write it like
'ignore' => function ($page) {
return $page->title()->value() === ['Accueil', 'Panier'];
}
or even
'ignore' => ['Accueil', 'Panier'];
Finally I don’t find the correct way to make it works.
With an array, you cannot use a simple ===
operator, but have to use in_array()
'ignore' => function ($page) {
return in_array( $page->title()->value(), ['Accueil', 'Panier']);
}
2 Likes
Untested, but this should work:
'cache' => [
'pages' => [
'active' => true,
'ignore' => function ($page) {
return in_array($page->id(), ['accueil', 'panier']);
}
]
]
Note that the ID is always lowercase. If you are checking for page titles instead, use in_array($page->title(), ['Accueil', 'Panier'])
.
@texnixe You beat me to it
Also note that to make this work, you should make sure to use a property that cannot be changed. So add something like
options:
changeSlug: false
changeTitle: false
depending on what property you use.
@sebastiangreger But we agree, so @Oziris can be super sure to trust our answers now
Oziris
August 1, 2020, 8:51am
6
Thank you both for the very very clear explanations