PHP code example of ray / psr-cache-module

1. Go to this page and download the library: Download ray/psr-cache-module 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/ */

    

ray / psr-cache-module example snippets


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
    ){}
}

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;
    }
}

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);

use Ray\PsrCacheModule\Psr6NullModule;

new Psr6NullModule();

use Ray\PsrCacheModule\Psr6ArrayModule;

new Psr6ArrayModule();

use Ray\PsrCacheModule\Psr6ApcuModule;

new Psr6ApcuModule();

use Ray\PsrCacheModule\Psr6RedisModule;

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

use Ray\PsrCacheModule\Psr6MemcachedModule;

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

use Ray\PsrCacheModule\Psr16CacheModule;

new Psr16CacheModule();

use Ray\PsrCacheModule\CacheDirModule;

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

use Ray\PsrCacheModule\CacheNamespaceModule;

new CacheNamespaceModule('app1');