PHP code example of consik / yii2-cachecleaner

1. Go to this page and download the library: Download consik/yii2-cachecleaner library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

consik / yii2-cachecleaner example snippets



...
if (!$model = Yii::$app->cache->get('cachedModel')) {
	$model = ARModel::findOne($modelID);
	Yii::$app->cache->set('cachedModel', $model);
}
...


public function behaviors()
{
    return [[
        'class' => CacheCleanerBehavior::className(),
        //'cacheComponent' => 'cache',  //you can define your app cache component
        'events' => [
            ActiveRecord::EVENT_AFTER_UPDATE => 'cachedModel'
            ActiveRecord::EVENT_BEFORE_DELETE => 'cachedModel'
        ]
    ]];
}


public function behaviors()
{
    return [[
        'class' => CacheCleanerBehavior::className(),
        'events' => [
            YOUR_EVENT_NAME => null
        ]
    ]];
}

...

function someComponentAction()
{
...
	$this->trigger(YOUR_EVENT_NAME, new CacheUpdateEvent([
		'keys' => ['keyName1', 'keyName2'],
	]));
...
}
 array $events = []
 array $attributes = []