seworqs/commons-cache

A lightweight PSR-16 cache manager with multi-namespace support, configurable Symfony adapters, and TTL handling.

2.0.0 2025-05-19 12:35 UTC

This package is auto-updated.

Last update: 2025-05-19 12:37:46 UTC


README

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.

Installation

composer require seworqs/commons-cache

Basic Usage (stand-alone)

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 Options

You may use:

✅ Aliases:

  • 'array'
  • 'filesystem'
  • 'null'

✅ Full class names:

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

✅ Ready-to-use instances:

'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.

Laminas Integration

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

Use via dependency injection:

public function __construct(private CacheManagerInterface $cacheManager) {}

Testing

composer test

Runs PHPUnit using in-memory adapters.

License

Apache-2.0, see LICENSE

About SEworqs

Seworqs builds clean, reusable modules for PHP and Mendix developers.

Learn more at github.com/seworqs

Badges

Latest Version Total Downloads License PHP Version Made by SEworqs