-
-
Notifications
You must be signed in to change notification settings - Fork 453
[V6˖] Act on all instances
Georges.L edited this page Feb 20, 2020
·
2 revisions
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:
<?php
/**
* @author Khoa Bui (khoaofgod) <[email protected]> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <[email protected]>
*/
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) <[email protected]> http://www.phpfastcache.com
* @author Georges.L (Geolim4) <[email protected]>
*/
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.
❓ Finally, if you need help, always check out the inevitable README.md