PHP code example of nytris / cache

1. Go to this page and download the library: Download nytris/cache 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/ */

    

nytris / cache example snippets




declare(strict_types=1);

use Nytris\Boot\BootConfig;
use Nytris\Boot\PlatformConfig;
use Nytris\Cache\Adapter\ReactCacheAdapter;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;

$bootConfig = new BootConfig(new PlatformConfig(__DIR__ . '/var/cache/nytris/'));

$bootConfig->installPackage(new MyNytrisPackage(
    // Using Symfony Cache adapter as an example.
    cachePoolFactory: fn (string $cachePath) => new ReactCacheAdapter(
        new FilesystemAdapter(
            'my_cache_key',
            0,
            $cachePath
        )
    )
));

return $bootConfig;



declare(strict_types=1);

use Nytris\Cache\Adapter\LightApcuAdapter;

$adapter = new LightApcuAdapter(
    namespace: 'my_namespace', // Defaults to the empty string.
    defaultLifetime: 3600      // Defaults to 0 / no expiry.
);

$cacheItem = $adapter->getItem('my_key');
$cacheItem->set('my_value');
$cacheItem->expiresAfter(2); // Set to expire 2 seconds from now.

$adapter->save($cacheItem);