Hi,
is there a way to generate the cache for my whole site on page update ?
I use staticache, and I can wait few seconds on every update.
I tried with site()->visit()
, $page->render()
, but no sucess.
Thanks
Hi,
is there a way to generate the cache for my whole site on page update ?
I use staticache, and I can wait few seconds on every update.
I tried with site()->visit()
, $page->render()
, but no sucess.
Thanks
Where? What exactly?
since the staticache plugin is a „pages cache“ it should be flushed on any page update by default (full cache independent of which page was updated)
I don’t want to flush the cache, what I try to achieve is to flush and then recontruct the cache.
Staticache is so fast that my idea is to have a “static” website on every page update.
The cache is flushed anyway whenever you make changes.
Again, what exactly have you tried to re-build the entire cache?
I tried this to alway have an up to date cache (static), but maybe it’s overkill…
So you don’t want to post the code your tried?
'hooks' => [
'page.update:after' => function ($newPage) {
foreach(site()->index() as $p){
try {
renderPage($p->id());
} catch(Exception $e) {
return $e;
}
}
}
]
function renderPage(string $pageId) {
$page = page($pageId);
if (kirby()->languages()->count() > 1) {
$content = $page->render();
foreach (kirby()->languages() as $lang) {
site()->visit($page, $lang->code());
$page->render();
}
} else {
site()->visit($page);
$page->render();
}
}
Should work, although
This line is pretty useless
And
And here it would make more sense to pass the page object, instead of the id, just to try and get the page again within the renderPage
method.
'hooks' => [
'page.update:after' => function ($newPage) {
foreach(site()->index() as $p){
try {
renderPage($p);
} catch(Exception $e) {
return $e;
}
}
}
]
------------
------------
function renderPage($page) {
if (kirby()->languages()->count() > 1) {
foreach (kirby()->languages() as $lang) {
site()->visit($page, $lang->code());
$page->render();
}
} else {
site()->visit($page);
$page->render();
}
}
It’s better, but it doesn’t work.
I can’t find the doc or source code for the site visit() method.
What I’m wondering: Doesn’t this hook show an error in the Panel for you when saving?
No error, no error in logs.
It takes 10 or 20 seconds when I update a page, so I think the $page->render()
function is executed, but the cache is still empty.
maybe the hook gets executed before the update call triggers the flush. thus you are rendering and then it get flushed.
Oh, I hadn’t thought about that at all…
Is there a way to verify that behavior ?
@bnomei is right. The after hook gets triggered before the cache is flushed: kirby/src/Cms/PageActions.php at main · getkirby/kirby · GitHub
Feel free to open an issue (Sign in to GitHub · GitHub) if you think this should be changed.
Thank you.
I made a suggestion.