Best way to call a custom function on event 'on_page_add' and 'on_page_delete'

Permalink
Hello All,
I am working on refresh cache for auto and page list when a new page add or delete.
I have on custom function that i want to call when these event get execute.

My call of event is like :
Events::addListener('on_page_delete', array($this, 'CacheBlockClearOn'));
Events::addListener('on_page_add', array($this, 'CacheBlockClearOn'));


I have add this in 'public function on_start()' in core block controller file. But it not working with full page cache enabled.

After that i have add this in core 'Package' class in src\package\package.php , this work with the event
Events::addListener('on_page_version_approve', array($this, 'CacheBlockClearOn'));


this will work but the problem is 'on_page_add' and 'on_page_delete' events not get execute so unable to refresh cache.

Can anybody tell me the better solution to add this event so this can execute every time page add or delete?

Or provide me better solution to do same.

Thanks in advance.

 
JohntheFish replied on at Permalink Reply
JohntheFish
You can put your on_start handler in a package controller, then set up all the other event handlers from there.
avdevs replied on at Permalink Reply
Hello @johntheFish,

I have tried with this file core 'Package' class in src\package\package.php, but here only ''on_page_version_approve'' event works.
So do you mean this file?
Or i have to create new package and in that i have setup all my event handlers?
mesuva replied on at Permalink Reply
mesuva
John is suggesting that you include this handling code in a new package.

Create a package called auto_cache and put the following code in controller.php :
<?php
namespace Concrete\Package\AutoCache;
use Package;
use Events;
class Controller extends Package {
    protected $pkgHandle = 'auto_cache';
    protected $appVersionRequired = '5.7.3';
    protected $pkgVersion = '0.9';
    public function getPackageDescription() {
        return t("A package to automatically trigger cache flushes");
    }
    public function getPackageName() {
        return t("Auto Cache");
    }
    public function install() {



Similar example here:https://github.com/Mesuva/snipcart_callback...
avdevs replied on at Permalink Reply
Hello Mesuva,
I have create package but on_start not working when full page cache is enabled. so i want the solution for this specially. Do you have better solution for this.
JohntheFish replied on at Permalink Reply
JohntheFish
No c5 events are run when the full page cache is enabled.
mesuva replied on at Permalink Reply
mesuva
If you can't turn full page caching off, the only thing I can suggest is the trigger of a cache flush by way of an automated job and a cron job.