Skip to content

[V6˖] Psr16 adapter

Georges.L edited this page Feb 23, 2022 · 4 revisions

As of the V6 an helper is now available to allow you to make use of the Psr16 adapter.

/**
 *
 * This file is part of Phpfastcache.
 *
 * @license MIT License (MIT)
 *
 * For full copyright and license information, please see the docs/CREDITS.txt and LICENCE files.
 *
 * @author Georges.L (Geolim4)  <contact@geolim4.com>
 * @author Contributors  https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
 */

use Phpfastcache\Helper\Psr16Adapter;

chdir(__DIR__);
require_once __DIR__ . '/../vendor/autoload.php';
$defaultDriver = (!empty($argv[1]) ? ucfirst($argv[1]) : 'Files');
$Psr16Adapter = new Psr16Adapter($defaultDriver, [/* Config array */]);

if(!$Psr16Adapter->has('test-key')){
    $nastyStuff = 'Database/webservice/etc operations';
    $Psr16Adapter->set('test-key', $nastyStuff);
}else{
    $value = $Psr16Adapter->get('test-key');
}

⚠️ The Psr16 adapter does not allow you to discriminate a null-stored value of a non-stored value value in contrast to a Psr6 architecture.