1. Go to this page and download the library: Download php-pico/caching 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/ */
use PhpPico\Caching\CachePool;
use PhpPico\Caching\Driver\Filesystem\FilesystemDriver;
$pool = new CachePool(new FilesystemDriver('/var/cache/app'));
$item = $pool->getItem('user.42');
if (!$item->isHit()) {
$item->set(['name' => 'Ada'])->expiresAfter(3600);
$pool->save($item);
}
$item->get(); // ['name' => 'Ada']
$pool->hasItem('user.42'); // true
$pool->deleteItem('user.42');
$pool->clear();
$pool->saveDeferred($pool->getItem('a')->set(1));
$pool->saveDeferred($pool->getItem('b')->set(2));
$pool->hasItem('a'); // true (visible before commit)
$pool->commit(); // persist both
use PhpPico\Caching\Cache;
use PhpPico\Caching\Driver\Testing\NoopDriver;
use PhpPico\Caching\Driver\Testing\StaticDriver;
use PhpPico\Caching\Driver\Filesystem\FilesystemDriver;
new Cache(new StaticDriver());
new Cache(new NoopDriver());
new Cache(new FilesystemDriver('/var/cache/app'));
use PhpPico\Caching\Cache;
use PhpPico\Caching\Driver\Redis\RedisConnection;
use PhpPico\Caching\Driver\Redis\RedisDriver;
$connection = RedisConnection::build(
host: '127.0.0.1',
port: 6379,
timeoutSeconds: 3,
database: 0,
reconnectTries: 1,
);
$cache = new Cache(new RedisDriver($connection));