Search by

ray / psr-cache-module

koriym

PSR-6 PSR-16 cache module for Ray.Di

Package info

github.com/ray-di/Ray.PsrCacheModule

pkg:composer/ray/psr-cache-module

Statistics

Installs: 492 558

Dependents: 5

Suggesters: 0

Stars: 1

Open Issues: 0

1.6.0 2026-10-28 06:42 UTC

README

codecov Type Coverage Continuous Integration Psalm level

This package is the Ray.Di module that performs the PSR-6 / PSR-16 interface binding.

You can use the PSR6 cache interface in two ways: Local and Public. Local is for caches that do not need to be shared among multiple web servers, and Public is for caches that need to be shared.

use Psr\Cache\CacheItemPoolInterface;
use Ray\PsrCacheModule\Annotation\Local;
use Ray\PsrCacheModule\Annotation\Shared;

class Foo
{
    public function __construct(
        #[Local] private CacheItemPoolInterface $localPool, 
        #[Shared] private CacheItemPoolInterface $sharedPool
    ){}
}

Create object graph

use Ray\Di\AbstractModule;
use Ray\Di\Injector;
use Ray\PsrCacheModule\Psr6ArrayModule;

$foo = (new Injector(new class extends AbstractModule {
    protected function configure()
    {
        $this->install(new Psr6ArrayModule()); // PSR-6 
        // $this->install(new Psr16CacheModule()); // PSR-16
    }
}))->getInstance(Foo::class);

assert($foo instanceof Foo);

Installation

composer require ray/psr-cache-module

Module install

PSR-6

Psr6NullModule

This module is for the development.

  • Local: Null
  • Shared: Null
use Ray\PsrCacheModule\Psr6NullModule;

new Psr6NullModule();

Psr6ArrayModule

This module is for the development.

  • Local: Array
  • Shared: Array
use Ray\PsrCacheModule\Psr6ArrayModule;

new Psr6ArrayModule();

Psr6ApcuModule

This module is for a standalone server

  • Local: Chain(APC, File)
  • Shared: Chain(APC, File)
use Ray\PsrCacheModule\Psr6ApcuModule;

new Psr6ApcuModule();

Psr6RedisModule

This module is for multiple servers.

  • Local: Chain(APC, File)
  • Shared: Redis
use Ray\PsrCacheModule\Psr6RedisModule;

new Psr6RedisModule('redis1:6379:1'); // host:port:dbIndex

Psr6MemcachedModule

This module is for multiple servers.

use Ray\PsrCacheModule\Psr6MemcachedModule;

new Psr6MemcachedModule('memcached1:11211:60,memcached2:11211:33');  // host:port:weight

See https://www.php.net/manual/en/memcached.addservers.php

PSR-16

If you install Psr16CacheModule, the cache engine installed with Psr6*Module can be used with PSR-16 interface. PSR-16 bindings use PSR-6 bindings.

use Ray\PsrCacheModule\Psr16CacheModule;

new Psr16CacheModule();

Common Configuration Module

CacheDirModule

Specifies the cache directory. Optional.

use Ray\PsrCacheModule\CacheDirModule;

new CacheDirModule('path/to/dir');

CacheNamespaceModule

Specifies the cache namespace (when multiple applications are placed on a single cache server). Optional.

use Ray\PsrCacheModule\CacheNamespaceModule;

new CacheNamespaceModule('app1');

Technical Note

Redis, Memcached classes and symfony/cache adapters are not serializable, but RedisAdapter and MemcachedAdapter, which inherit from symfony/cache and are provided in this package, are.