PHP code example of seworqs / commons-cache

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

    

seworqs / commons-cache example snippets


use Seworqs\Commons\Cache\CacheManagerFactory;

$config = [
    'namespaces' => [
        'default' => [
            'adapter' => 'array',
            'ttl' => 3600,
        ],
        'menu' => [
            'adapter' => 'filesystem',
            'ttl' => 600,
            'directory' => __DIR__ . '/cache/menu',
        ],
    ],
];

$manager = CacheManagerFactory::create($config);

$cache = $manager->getNamespace();
$cache->set('foo', 'bar');
$value = $cache->get('foo');

'adapter' => Symfony\Component\Cache\Adapter\PhpFilesAdapter::class

'adapter' => new Symfony\Component\Cache\Adapter\RedisAdapter($redisClient, 'namespace', 600)

'factories' => [
    Seworqs\Commons\Cache\CacheManagerInterface::class => Seworqs\Commons\Cache\CacheManagerFactory::class,
],

public function __construct(private CacheManagerInterface $cacheManager) {}