PHP code example of yii1tech / tagged-cache

1. Go to this page and download the library: Download yii1tech/tagged-cache 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/ */

    

yii1tech / tagged-cache example snippets




return [
    'components' => [
        'cache' => [
            'class' => \yii1tech\cache\tagged\MemCache::class, // implements `\yii1tech\cache\tagged\TagAwareCacheContract`
            'servers' => [
                [
                    'host' => 'memcache.server',
                    'port' => 11211,
                    'weight' => 100,
                ],
            ],
        ],
        // ...
    ],
    // ...
];



$cacheKey = 'example-cache-key';
$value = Yii::app()->cache->get($cacheKey);
if ($value === false) {
    $value = Yii::app()->db->createCommand('SELECT ...')->query(); // some heave SQL query.
    
    Yii::app()->cache->set(
        $cacheKey, // cache key
        $value, // value to be cached
        3600, // cache expiration
        null, // dependency, empty in our case
        ['database', 'main'] // list of cache tags.
    );
}



Yii::app()->cache->invalidateTags(['database']);