A lightweight PSR-16 cache manager with multi-namespace support, configurable Symfony adapters, and TTL handling.
Built on top of symfony/cache, fully compatible with PHP 8.1+ and PSR standards.
composer require seworqs/commons-cacheuse 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');You may use:
'array''filesystem''null'
'adapter' => Symfony\Component\Cache\Adapter\PhpFilesAdapter::class'adapter' => new Symfony\Component\Cache\Adapter\RedisAdapter($redisClient, 'namespace', 600)Other adapters like Redis, Memcached, or PDO can be used by providing their full class name and handling construction yourself.
'factories' => [
Seworqs\Commons\Cache\CacheManagerInterface::class => Seworqs\Commons\Cache\CacheManagerFactory::class,
],Use via dependency injection:
public function __construct(private CacheManagerInterface $cacheManager) {}composer testRuns PHPUnit using in-memory adapters.
Apache-2.0, see LICENSE
Seworqs builds clean, reusable modules for PHP and Mendix developers.
Learn more at github.com/seworqs