ray / psr-cache-module
Installs: 178 055
Dependents: 4
Suggesters: 0
Security: 0
Stars: 1
Watchers: 5
Forks: 3
Open Issues: 1
Requires
- php: ^7.3 || ^8.0
- doctrine/annotations: ^1.13
- psr/cache: ^1.0.1 || ^2.0 || ^3.0
- psr/simple-cache: ^1.0 || ^2.0 || ^3.0
- ray/aop: ^2.10.4
- ray/di: ^2.13.2
- symfony/cache: ^5.3.4 || ^6.0
Requires (Dev)
- ext-memcached: *
- ext-redis: *
- bamarni/composer-bin-plugin: ^1.4
- phpunit/phpunit: ^9.5.28
README
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.
PHP8
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 ){} }
PHP7.4
use Psr\Cache\CacheItemPoolInterface; use Ray\PsrCacheModule\Annotation\Local; use Ray\PsrCacheModule\Annotation\Shared; class Foo { private CacheItemPoolInterface $localPool; private CacheItemPoolInterface $sharedPool; /** * @Local('localPool') * @Shared('sharedPool') */ public function __construct( CacheItemPoolInterface $localPool, CacheItemPoolInterface $sharedPool ){ $this->localPool = $localPool; $this->sharedPool = $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.
- Local: Chain(APC, File)
- Shared: Memcached
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.