Hi,
I am running GRAV on hosting with LiteSpeed Cache. Caching is working great, but I have to manually clear cache each time I made change on pages as I couldn’t find any plugin for GRAV (use command curl -i -X PURGE https://page-url
).
What I am trying to achieve is plugin that will purge page from cache after admin save.
Just for testing purposes I create .php file on root folder with code
<?php header('X-LiteSpeed-Purge: /page-url'); ?>
and it is working fine each time I hit file.
So now I am trying to use this code in plugin with onAdminAfterSave
function - but without any success.
Will be great to get any suggestions from U
I will reply to myself, as I find part solution…
public function onPluginsInitialized()
{
if ($this->isAdmin()) {
$this->enable([
'onAdminAfterSave' => ['onAdminAfterSave', 0]
]);
return;
}
}
public function onAdminAfterSave(Event $event)
{
header('X-LiteSpeed-Purge: *');
}
this will Purge all pages from LiteSpeed Cache after pressing Save button…
Now question is how to purge (get /page-url) only for edited page?
@lisekbox,
Now question is how to purge (get /page-url) only for edited page?
Try something like:
public function onAdminAfterSave(Event $event)
{
$object = $event['object'];
if ($object instanceof PageObject) {
$route = $object->route();
header("X-LiteSpeed-Purge: $route");
}
}
1 Like
Thanks!
It didn’t work but it it was so close!
I made only small change in your code (PageObject → PageInterface)
public function onAdminAfterSave(Event $event)
{
$object = $event['object'];
if ($object instanceof PageInterface) {
$route = $object->route();
header("X-LiteSpeed-Purge: $route");
}
}
@lisekbox, According the debugger the $event['object']
should be a PageObject
, which also implements interface PageInterface
…
Just to nitpick, $object
should be used in the if-statement. 
1 Like
ahh… I was testing many versions that’s why I miss that… Thanks - I just made correction 
when PageObject is in if-statement page headers didn’t change after saving (x-litespeed-cache: hit), so I remove if-statement and it worked - I get cache: miss , but leaving code like that will cause error when saving on other places - for example when making updates on plugin settings, so I tried PageInterface and it works
Once again Thanks a lot!