-
-
Notifications
You must be signed in to change notification settings - Fork 453
[V7˖] Override a core driver | Setup a custom driver
🆕 As of the V7 there is a cleaner way to use a custom driver or to override a core driver.
This feature is pretty easy actually:
<?php
use Phpfastcache\CacheManager;
use Phpfastcache\Drivers\Fakefiles\Config;
$driverName = 'Fakefiles';
$className = \Phpfastcache\Drivers\Fakefiles\Driver::class;
CacheManager::addCustomDriver($driverName, $className);
$cacheInstance = CacheManager::getInstance($driverName, new Config(['customOption' => true]));
The only requirement is that $className
MUST implements \Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface
.
Once you done you can remove * the custom driver easily:
<?php
use Phpfastcache\CacheManager;
CacheManager::removeCustomDriver('Fakefiles');
This feature is pretty close of adding a custom driver, except that $driverName
MUST be an existing core driver.
<?php
use Phpfastcache\CacheManager;
use Phpfastcache\Drivers\Fakefiles\Config;
$driverName = 'Files';
$className = \Phpfastcache\DriverTest\Files2\Driver::class;
CacheManager::addCoreDriverOverride($driverName, $className);
$cacheInstance = CacheManager::getInstance($driverName, new Config(['customOption' => true]));
However, here $className
MUST extends the base class provided by the Phpfastcache core (which implicitly implements \Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface
).
Once you done you can remove * the driver override easily:
<?php
use Phpfastcache\CacheManager;
CacheManager::removeCoreDriverOverride('Files');
* Please note that removing overrides/custom drivers only apply to the next cache instance generated by the cacheManager. It will NOT update actual instance that have been already generated.
CacheManager::setNamespacePath()
is now deprecated.
❓ Finally, if you need help, always check out the inevitable README.md