Skip to content

[V6˖] Act on all instances

Georges.L edited this page Feb 20, 2020 · 2 revisions

⚠️ Please note that this feature has been removed as of the V8

⚠️ It's been replaced by aggregated cluster support, see migration guide


Sometimes you may need to make an operation over all instanced drivers. As of the V6 an helper is now available to make those operations easier:

Getting statistics of all instanced drivers:

<?php

/**
 * @author Khoa Bui (khoaofgod)  <khoaofgod@gmail.com> http://www.phpfastcache.com
 * @author Georges.L (Geolim4)  <contact@geolim4.com>
 */
use phpFastCache\CacheManager;
use phpFastCache\Entities\driverStatistic;
use phpFastCache\Helper\ActOnAll;


chdir(__DIR__);
require_once __DIR__ . '/../vendor/autoload.php';

$defaultDriver = (!empty($argv[1]) ? ucfirst($argv[1]) : 'Files');
$status = 0;
echo "Testing ActOnAll helper\n";

/**
 * Testing memcached as it is declared in .travis.yml
 */
$filesInstance = CacheManager::getInstance('Files');
$RedisInstance = CacheManager::getInstance('Redis');
$MemcacheInstance = CacheManager::getInstance('Memcached');

$actOnAll = new ActOnAll();
$statsAry = $actOnAll->getStats();

As you can see, $statsAry will contains an array of driver's statistics. This is not the only use case, you can also delete many item by their name:

<?php

/**
 * @author Khoa Bui (khoaofgod)  <khoaofgod@gmail.com> http://www.phpfastcache.com
 * @author Georges.L (Geolim4)  <contact@geolim4.com>
 */
use phpFastCache\CacheManager;
use phpFastCache\Entities\driverStatistic;
use phpFastCache\Helper\ActOnAll;


chdir(__DIR__);
require_once __DIR__ . '/../vendor/autoload.php';

$defaultDriver = (!empty($argv[1]) ? ucfirst($argv[1]) : 'Files');
$status = 0;
echo "Testing ActOnAll helper\n";

/**
 * Testing memcached as it is declared in .travis.yml
 */
$filesInstance = CacheManager::getInstance('Files');
$RedisInstance = CacheManager::getInstance('Redis');
$MemcacheInstance = CacheManager::getInstance('Memcached');

$actOnAll = new ActOnAll();
$actOnAll->deleteItem('ItemName');

The full list of available methods is available here.