, (*1)
PSR-11 PHP Cache
PHP Cache Factories for PSR-11, (*2)
Table of Contents
Installation
composer require wshafer/psr11-phpcache
Usage
<?php
// Get a pool
$pool = $container->get('myCacheServiceName');
// Get an item (existing or new)
$item = $pool->getItem('cache_key');
// Set some values and store
$item->set('value');
$item->expiresAfter(60);
$pool->save($item);
// Verify existence
$pool->hasItem('cache_key'); // True
$item->isHit(); // True
// Get stored values
$myValue = $item->get();
echo $myValue; // "value"
// Delete
$pool->deleteItem('cache_key');
$pool->hasItem('cache_key'); // False
Additional info can be found in the documentation, (*3)
Containers
Any PSR-11 container wil work. In order to do that you will need to add configuration
and register the factory \WShafer\PSR11PhpCache\PhpCacheFactory(), (*4)
Below are some specific container examples to get you started, (*5)
Pimple Example
// Create Container
$container = new \Xtreamwayz\Pimple\Container([
// Cache using the default keys.
'cache' => new \WShafer\PSR11PhpCache\PhpCacheFactory(),
// Another Cache using a different cache configuration
'otherCache' => function($c) {
return \WShafer\PSR11PhpCache\PhpCacheFactory::cacheTwo($c);
},
'config' => [
'caches' => [
/*
* At the bare minimum you must include a default cache config.
* Otherwise a void cache will be used and operations will be
* be sent to the void.
*/
'default' => [
'type' => 'void', // Required : Type of adapter
'namespace' => 'my-namespace', // Optional : Namespace
'prefix' => 'prefix_', // Optional : Prefix. If a Namespace is configured and the adapter supports it, the Namespace will me used instead.
'logger' => 'my-logger', // Optional : PSR-1 Logger Service Name
'options' => [], // Optional : Adapter Specific Options
],
// Another Cache
'cacheTwo' => [
'type' => 'memcached', // Required : Type of adapter
'namespace' => 'my-namespace', // Optional : Namespace
'prefix' => 'prefix_', // Optional : Prefix. If a Namespace is configured and the adapter supports it, the Namespace will me used instead.
'logger' => 'my-logger', // Optional : PSR-1 Logger Service Name
'options' => [], // Optional : Adapter Specific Options
],
// Cache Chain
'chained' => [
'type' => 'chain', // Required : Type of adapter
'options' => [
'services' => ['default', 'cacheTwo'], // Required : An array of pre-configured cache service names
'skipOnFailure' => false, // Optional : If true we will remove a pool form the chain if it fails. (Default: false)
]
],
],
],
]);
Zend Service Manager
$container = new \Zend\ServiceManager\ServiceManager([
'factories' => [
// Cache using the default keys.
'cache' => \WShafer\PSR11PhpCache\PhpCacheFactory::class,
// Another Cache using a different cache configuration
'otherCache' => [\WShafer\PSR11PhpCache\PhpCacheFactory::class, 'cacheTwo'],
]
]);
$container->setService('config', [
'caches' => [
/*
* At the bare minimum you must include a default cache config.
* Otherwise a void cache will be used and operations will be
* be sent to the void.
*/
'default' => [
'type' => 'void', // Required : Type of adapter
'namespace' => 'my-namespace', // Optional : Namespace
'prefix' => 'prefix_', // Optional : Prefix. If a Namespace is configured and the adapter supports it, the Namespace will me used instead.
'logger' => 'my-logger', // Optional : PSR-1 Logger Service Name
'options' => [], // Optional : Adapter Specific Options
],
// Another Cache
'cacheTwo' => [
'type' => 'memcached', // Required : Type of adapter
'namespace' => 'my-namespace', // Optional : Namespace
'prefix' => 'prefix_', // Optional : Prefix. If a Namespace is configured and the adapter supports it, the Namespace will me used instead.
'logger' => 'my-logger', // Optional : PSR-1 Logger Service Name
'options' => [], // Optional : Adapter Specific Options
],
// Cache Chain
'chained' => [
'type' => 'chain', // Required : Type of adapter
'options' => [
'services' => ['default', 'cacheTwo'], // Required : An array of pre-configured cache service names
'skipOnFailure' => false, // Optional : If true we will remove a pool form the chain if it fails. (Default: false)
]
],
],
]);
Laminas Service Manager
$container = new \Laminas\ServiceManager\ServiceManager([
'factories' => [
// Cache using the default keys.
'cache' => \WShafer\PSR11PhpCache\PhpCacheFactory::class,
// Another Cache using a different cache configuration
'otherCache' => [\WShafer\PSR11PhpCache\PhpCacheFactory::class, 'cacheTwo'],
]
]);
$container->setService('config', [
'caches' => [
/*
* At the bare minimum you must include a default cache config.
* Otherwise a void cache will be used and operations will be
* be sent to the void.
*/
'default' => [
'type' => 'void', // Required : Type of adapter
'namespace' => 'my-namespace', // Optional : Namespace
'prefix' => 'prefix_', // Optional : Prefix. If a Namespace is configured and the adapter supports it, the Namespace will me used instead.
'logger' => 'my-logger', // Optional : PSR-1 Logger Service Name
'options' => [], // Optional : Adapter Specific Options
],
// Another Cache
'cacheTwo' => [
'type' => 'memcached', // Required : Type of adapter
'namespace' => 'my-namespace', // Optional : Namespace
'prefix' => 'prefix_', // Optional : Prefix. If a Namespace is configured and the adapter supports it, the Namespace will me used instead.
'logger' => 'my-logger', // Optional : PSR-1 Logger Service Name
'options' => [], // Optional : Adapter Specific Options
],
// Cache Chain
'chained' => [
'type' => 'chain', // Required : Type of adapter
'options' => [
'services' => ['default', 'cacheTwo'], // Required : An array of pre-configured cache service names
'skipOnFailure' => false, // Optional : If true we will remove a pool form the chain if it fails. (Default: false)
]
],
],
]);
Frameworks
Any framework that use a PSR-11 should work fine. Below are some specific framework examples to get you started, (*6)
Zend Expressive
You'll need to add configuration and register the services you'd like to use. There are number of ways to do that
but the recommended way is to create a new config file config/autoload/cache.global.php
, (*7)
Configuration
config/autoload/cache.global.php, (*8)
<?php
return [
'dependencies' => [
'factories' => [
// Cache using the default keys.
'cache' => \WShafer\PSR11PhpCache\PhpCacheFactory::class,
// Another Cache using a different cache configuration
'otherCache' => [\WShafer\PSR11PhpCache\PhpCacheFactory::class, 'cacheTwo'],
]
],
'caches' => [
/*
* At the bare minimum you must include a default cache config.
* Otherwise a void cache will be used and operations will be
* be sent to the void.
*/
'default' => [
'type' => 'void', // Required : Type of adapter
'namespace' => 'my-namespace', // Optional : Namespace
'prefix' => 'prefix_', // Optional : Prefix. If a Namespace is configured and the adapter supports it, the Namespace will me used instead.
'logger' => 'my-logger', // Optional : PSR-1 Logger Service Name
'options' => [], // Optional : Adapter Specific Options
],
// Another Cache
'cacheTwo' => [
'type' => 'memcached', // Required : Type of adapter
'namespace' => 'my-namespace', // Optional : Namespace
'prefix' => 'prefix_', // Optional : Prefix. If a Namespace is configured and the adapter supports it, the Namespace will me used instead.
'logger' => 'my-logger', // Optional : PSR-1 Logger Service Name
'options' => [], // Optional : Adapter Specific Options
],
// Cache Chain
'chained' => [
'type' => 'chain', // Required : Type of adapter
'options' => [
'services' => ['default', 'cacheTwo'], // Required : An array of pre-configured cache service names
'skipOnFailure' => false, // Optional : If true we will remove a pool form the chain if it fails. (Default: false)
]
],
],
];
Zend Framework 3
You'll need to add configuration and register the services you'd like to use. There are number of ways to do that
but the recommended way is to create a new config file config/autoload/cache.global.php
, (*9)
Configuration
config/autoload/cache.global.php, (*10)
<?php
return [
'service_manager' => [
'factories' => [
// Cache using the default keys.
'cache' => \WShafer\PSR11PhpCache\PhpCacheFactory::class,
// Another Cache using a different cache configuration
'otherCache' => [\WShafer\PSR11PhpCache\PhpCacheFactory::class, 'cacheTwo'],
]
],
'caches' => [
/*
* At the bare minimum you must include a default cache config.
* Otherwise a void cache will be used and operations will be
* be sent to the void.
*/
'default' => [
'type' => 'void', // Required : Type of adapter
'namespace' => 'my-namespace', // Optional : Namespace
'prefix' => 'prefix_', // Optional : Prefix. If a Namespace is configured and the adapter supports it, the Namespace will me used instead.
'logger' => 'my-logger', // Optional : PSR-1 Logger Service Name
'options' => [], // Optional : Adapter Specific Options
],
// Another Cache
'cacheTwo' => [
'type' => 'memcached', // Required : Type of adapter
'namespace' => 'my-namespace', // Optional : Namespace
'prefix' => 'prefix_', // Optional : Prefix. If a Namespace is configured and the adapter supports it, the Namespace will me used instead.
'logger' => 'my-logger', // Optional : PSR-1 Logger Service Name
'options' => [], // Optional : Adapter Specific Options
],
// Cache Chain
'chained' => [
'type' => 'chain', // Required : Type of adapter
'options' => [
'services' => ['default', 'cacheTwo'], // Required : An array of pre-configured cache service names
'skipOnFailure' => false, // Optional : If true we will remove a pool form the chain if it fails. (Default: false)
]
],
],
];
Mezzio
You'll need to add configuration and register the services you'd like to use. There are number of ways to do that
but the recommended way is to create a new config file config/autoload/cache.global.php
, (*11)
Configuration
config/autoload/cache.global.php, (*12)
<?php
return [
'dependencies' => [
'factories' => [
// Cache using the default keys.
'cache' => \WShafer\PSR11PhpCache\PhpCacheFactory::class,
// Another Cache using a different cache configuration
'otherCache' => [\WShafer\PSR11PhpCache\PhpCacheFactory::class, 'cacheTwo'],
]
],
'caches' => [
/*
* At the bare minimum you must include a default cache config.
* Otherwise a void cache will be used and operations will be
* be sent to the void.
*/
'default' => [
'type' => 'void', // Required : Type of adapter
'namespace' => 'my-namespace', // Optional : Namespace
'prefix' => 'prefix_', // Optional : Prefix. If a Namespace is configured and the adapter supports it, the Namespace will me used instead.
'logger' => 'my-logger', // Optional : PSR-1 Logger Service Name
'options' => [], // Optional : Adapter Specific Options
],
// Another Cache
'cacheTwo' => [
'type' => 'memcached', // Required : Type of adapter
'namespace' => 'my-namespace', // Optional : Namespace
'prefix' => 'prefix_', // Optional : Prefix. If a Namespace is configured and the adapter supports it, the Namespace will me used instead.
'logger' => 'my-logger', // Optional : PSR-1 Logger Service Name
'options' => [], // Optional : Adapter Specific Options
],
// Cache Chain
'chained' => [
'type' => 'chain', // Required : Type of adapter
'options' => [
'services' => ['default', 'cacheTwo'], // Required : An array of pre-configured cache service names
'skipOnFailure' => false, // Optional : If true we will remove a pool form the chain if it fails. (Default: false)
]
],
],
];
Module Config
If you're not using the Zend Component Installer you will
also need to register the Module., (*13)
config/modules.config.php (ZF 3 skeleton), (*14)
<?php
return [
// ... Previously registered modules here
'WShafer\\PSR11PhpCache',
];
config/application.config.php (ZF 2 skeleton), (*15)
<?php
return [
'modules' => [
// ... Previously registered modules here
'WShafer\\PSR11PhpCache',
]
];
Slim
public/index.php, (*16)
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
require '../vendor/autoload.php';
// Add Configuration
$config = [
'settings' => [
'caches' => [
/*
* At the bare minimum you must include a default cache config.
* Otherwise a void cache will be used and operations will be
* be sent to the void.
*/
'default' => [
'type' => 'void', // Required : Type of adapter
'namespace' => 'my-namespace', // Optional : Namespace
'prefix' => 'prefix_', // Optional : Prefix. If a Namespace is configured and the adapter supports it, the Namespace will me used instead.
'logger' => 'my-logger', // Optional : PSR-1 Logger Service Name
'options' => [], // Optional : Adapter Specific Options
],
// Another Cache
'cacheTwo' => [
'type' => 'memcached', // Required : Type of adapter
'namespace' => 'my-namespace', // Optional : Namespace
'prefix' => 'prefix_', // Optional : Prefix. If a Namespace is configured and the adapter supports it, the Namespace will me used instead.
'logger' => 'my-logger', // Optional : PSR-1 Logger Service Name
'options' => [], // Optional : Adapter Specific Options
],
// Cache Chain
'chained' => [
'type' => 'chain', // Required : Type of adapter
'options' => [
'services' => ['default', 'cacheTwo'], // Required : An array of pre-configured cache service names
'skipOnFailure' => false, // Optional : If true we will remove a pool form the chain if it fails. (Default: false)
]
],
],
],
];
$app = new \Slim\App($config);
// Wire up the factory
$container = $app->getContainer();
// Register the service with the container.
$container['cache'] = new \WShafer\PSR11PhpCache\PhpCacheFactory();
$container['otherCache'] = function($c) {
return WShafer\PSR11PhpCache\PhpCacheFactory::cacheTwo($c);
};
Configuration
-
Named Services : These are services names wired up to a factory. The configuration will differ based on the
type of container / framework in use., (*17)
-
Adapters : Cache Pool config tell us what type of cache to use and how to connect to that cache.
Some caches provide other special options on how to handle the data and what data to handle. See the
appropriate apdaptor config below., (*18)
Minimal Configuration
A minimal configuration would consist of at least one default cache and one named service.
Please note that if you don't specify a default cache a Void pool will be used when
you wire up the default cache., (*19)
Minimal Example (using Zend Expressive for the example)
<?php
return [
'dependencies' => [
'factories' => [
// Cache using the default keys.
'cache' => \WShafer\PSR11PhpCache\PhpCacheFactory::class,
]
],
'caches' => [
/*
* At the bare minimum you must include a default cache config.
* Otherwise a void cache will be used and operations will be
* be sent to the void.
*/
'default' => [
'type' => 'apc', // Required : Type of adapter
'options' => [], // Optional : Adapter Specific Options
],
],
];
Full Configuration (using Zend Expressive for the example)
Full Example
<?php
return [
'dependencies' => [
'factories' => [
// Cache using the default keys.
'cache' => \WShafer\PSR11PhpCache\PhpCacheFactory::class,
// Another Cache using a different cache configuration
'otherCache' => [\WShafer\PSR11PhpCache\PhpCacheFactory::class, 'cacheTwo'],
]
],
'caches' => [
/*
* At the bare minimum you must include a default cache config.
* Otherwise a void cache will be used and operations will be
* be sent to the void.
*/
'default' => [
'type' => 'void', // Required : Type of adapter
'namespace' => 'my-namespace', // Optional : Namespace
'prefix' => 'prefix_', // Optional : Prefix. If a Namespace is configured and the adapter supports it, the Namespace will me used instead.
'logger' => 'my-logger', // Optional : PSR-1 Logger Service Name
'options' => [], // Optional : Adapter Specific Options
],
// Another Cache
'cacheTwo' => [
'type' => 'memcached', // Required : Type of adapter
'namespace' => 'my-namespace', // Optional : Namespace
'prefix' => 'prefix_', // Optional : Prefix. If a Namespace is configured and the adapter supports it, the Namespace will me used instead.
'logger' => 'my-logger', // Optional : PSR-1 Logger Service Name
'options' => [], // Optional : Adapter Specific Options
],
// Cache Chain
'chained' => [
'type' => 'chain', // Required : Type of adapter
'options' => [
'services' => ['default', 'cacheTwo'], // Required : An array of pre-configured cache service names
'skipOnFailure' => false, // Optional : If true we will remove a pool form the chain if it fails. (Default: false)
]
],
],
];
Adapters
APC
This is a PSR-6 cache implementation using Apc. It is a part of the PHP Cache organisation.
To read about features like tagging and hierarchy support please read the shared
documentation at www.php-cache.com., (*20)
Note: APC extension is not directly supported in PHP 7. You can use the APC_BC package on
PHP 7 for APCU backwards compatibility, but it is recommended
to simply the use the APCu cache below., (*21)
<?php
return [
'caches' => [
'myHandlerName' => [
'type' => 'apc',
'prefix' => 'prefix_', // Optional : Prefix. Namespaces are not supported on this adapter.
'logger' => 'my-logger', // Optional : PSR-1 Logger Service Name
'options' => [
'skipOnCli' => false, // Optional : Skip cache with CLI
],
],
],
];
Php Cache Docs: Apc PSR-6 Cache pool, (*22)
APCU
This is a PSR-6 cache implementation using Apcu. It is a part of the PHP Cache organisation.
To read about features like tagging and hierarchy support please read the shared
documentation at www.php-cache.com., (*23)
<?php
return [
'caches' => [
'myHandlerName' => [
'type' => 'apcu',
'prefix' => 'prefix_', // Optional : Prefix. Namespaces are not supported on this adapter.
'logger' => 'my-logger', // Optional : PSR-1 Logger Service Name
'options' => [
'skipOnCli' => false, // Optional : Skip cache with CLI
],
],
],
];
Php Cache Docs: Apcu PSR-6 Cache pool, (*24)
Array
This is a PSR-6 cache implementation using PHP array. It is a part of the PHP Cache organisation.
To read about features like tagging and hierarchy support please read the shared
documentation at www.php-cache.com., (*25)
<?php
return [
'caches' => [
'myHandlerName' => [
'type' => 'array',
'prefix' => 'prefix_', // Optional : Prefix. Namespaces are not supported on this adapter.
'logger' => 'my-logger', // Optional : PSR-1 Logger Service Name
'options' => [] // No options available,
],
],
];
Php Cache Docs: Array PSR-6 Cache pool, (*26)
File System
This is a PSR-6 cache implementation using Filesystem. It is a part of the PHP Cache organisation. To read about
features like tagging and hierarchy support please read the shared documentation at
www.php-cache.com., (*27)
This implementation is using the excellent Flysystem., (*28)
See: PSR-11 FlySystem for some pre-built factories to
get up and running quickly, (*29)
<?php
return [
'caches' => [
'myHandlerName' => [
'type' => 'fileSystem',
'prefix' => 'prefix_', // Optional : Prefix. Namespaces are not supported on this adapter.
'logger' => 'my-logger', // Optional : PSR-1 Logger Service Name
'options' => [
'flySystemService' => 'my-service', // Required : Pre-configured FlySystem service from the container
'folder' => 'cache', // Optional : Folder. Default: 'cache'
]
],
],
];
Php Cache Docs: Filesystem PSR-6 Cache pool, (*30)
Illuminate
This is a PSR-6 cache implementation using Illuminate cache. It is a part of the PHP Cache organisation.
To read about features like tagging and hierarchy support please read the shared documentation at
www.php-cache.com., (*31)
This is a PSR-6 to Illuminate bridge., (*32)
<?php
return [
'caches' => [
'myHandlerName' => [
'type' => 'illuminate',
'prefix' => 'prefix_', // Optional : Prefix. Namespaces are not supported on this adapter.
'logger' => 'my-logger', // Optional : PSR-1 Logger Service Name
'options' => [
'store' => 'my-service', // Required : Pre-configured illuminate store service from the container
]
],
],
];
Php Cache Docs: Illuminate PSR-6 Cache pool, (*33)
Memcache
This adaptor is not supported by this package as there is no official release of this driver for PHP 7.
Please use the Memcached adaptor instead., (*34)
Memcached
This is a PSR-6 cache implementation using Memcached. It is a part of the PHP Cache organisation.
To read about features like tagging and hierarchy support please read the shared documentation at
www.php-cache.com., (*35)
<?php
return [
'caches' => [
'myHandlerName' => [
'type' => 'memcached',
'namespace' => 'my-namespace', // Optional : Namespace
'prefix' => 'prefix_', // Optional : Prefix. If a Namespace is configured and the adapter supports it, the Namespace will me used instead.
'logger' => 'my-logger', // Optional : PSR-1 Logger Service Name
'options' => [
// A container service is required if no servers are provided : Pre-configured memcached service from the container.
'service' => 'my-service',
// Required if no service is provided : List of servers to add to pool. Must provide at least one server.
'servers' => [
'local' => [
'host' => '127.0.0.1',
'port' => 11211,
'weight' => 0
]
],
// Optional: List of Memcached options. See: http://php.net/manual/en/memcached.setoption.php
// Only set if servers are provided.
'memcachedOptions' => [
\Memcached::OPT_HASH => Memcached::HASH_MURMUR
],
// Optional : Persistent Id. Only used if servers are provided.
'persistentId' => 'some_id',
]
],
],
];
Php Cache Docs: Memcached PSR-6 Cache pool, (*36)
MongoDb
This is a PSR-6 cache implementation using MongoDB. It is a part of the PHP Cache organisation.
To read about features like tagging and hierarchy support please read the shared documentation at
www.php-cache.com., (*37)
<?php
return [
'caches' => [
'myHandlerName' => [
'type' => 'mongodb',
'prefix' => 'prefix_', // Optional : Prefix. Namespaces are not supported on this adapter.
'logger' => 'my-logger', // Optional : PSR-1 Logger Service Name
'options' => [
// A container service is required if no DSN is provided : Pre-configured Mongo Collection
// service from the container.
'service' => 'my-service',
// Required if no service is provided : DSN connection string
'dsn' => 'mongodb://127.0.0.1',
// Required if no service is provided : Database name to connect to.
'database' => 'some-db-name',
// Required if no service is provided : Collection name.
'collection' => 'some_collection',
]
],
],
];
Php Cache Docs: MongoDB PSR-6 Cache pool, (*38)
Predis
This is a PSR-6 cache implementation using Predis. It is a part of the PHP Cache organisation.
To read about features like tagging and hierarchy support please read the shared documentation at
www.php-cache.com., (*39)
This implementation is using Predis. If you want an adapter with
PhpRedis you should look at our
Redis adapter., (*40)
<?php
return [
'caches' => [
'fromService' => [
'type' => 'predis',
'namespace' => 'my-namespace', // Optional : Namespace
'prefix' => 'prefix_', // Optional : Prefix. If a Namespace is configured and the adapter supports it, the Namespace will me used instead.
'logger' => 'my-logger', // Optional : PSR-1 Logger Service Name
'options' => [
// A container service is required if no servers are provided : Pre-configured Predis Client
// service from the container.
'service' => 'my-service',
]
],
'singleConnection' => [
'type' => 'predis',
'namespace' => 'my-namespace', // Optional : Namespace
'prefix' => 'prefix_', // Optional : Prefix. If a Namespace is configured and the adapter supports it, the Namespace will me used instead.
'logger' => 'my-logger', // Optional : PSR-1 Logger Service Name
'options' => [
// Required if no service is provided : server(s)
'servers' => [
'tcp:/127.0.0.1:6379'
],
// Optional : Array of options to pass to the client
'connectionOptions' => [],
]
],
'singleConnectionUsingConnectionParams' => [
'type' => 'predis',
'namespace' => 'my-namespace', // Optional : Namespace
'prefix' => 'prefix_', // Optional : Prefix. If a Namespace is configured and the adapter supports it, the Namespace will me used instead.
'logger' => 'my-logger', // Optional : PSR-1 Logger Service Name
'options' => [
// Required if no service is provided : server(s)
'servers' => [
[
'scheme' => 'tcp',
'host' => '10.0.0.1',
'port' => 6379,
]
],
// Optional : Array of options to pass to the client
'connectionOptions' => [],
],
],
'cluster' => [
'type' => 'predis',
'namespace' => 'my-namespace', // Optional : Namespace
'prefix' => 'prefix_', // Optional : Prefix. If a Namespace is configured and the adapter supports it, the Namespace will me used instead.
'logger' => 'my-logger', // Optional : PSR-1 Logger Service Name
'options' => [
// Required if no service is provided : server(s)
'servers' => [
'tcp://10.0.0.1?alias=first-node',
['host' => '10.0.0.2', 'alias' => 'second-node'],
],
// Optional : Array of options to pass to the client
'connectionOptions' => ['cluster' => 'redis'],
],
]
],
];
Note: For more connection options please see the Predis docs., (*41)
Php Cache Docs: Predis PSR-6 Cache pool, (*42)
Redis
This is a PSR-6 cache implementation using Redis. It is a part of the PHP Cache organisation.
To read about features like tagging and hierarchy support please read the shared documentation at
www.php-cache.com., (*43)
This implementation is using PhpRedis. If you want an adapter with
Predis you should look at our Predis adapter., (*44)
<?php
return [
'caches' => [
'fromService' => [
'type' => 'redis',
'namespace' => 'my-namespace', // Optional : Namespace
'prefix' => 'prefix_', // Optional : Prefix. If a Namespace is configured and the adapter supports it, the Namespace will me used instead.
'logger' => 'my-logger', // Optional : PSR-1 Logger Service Name
'options' => [
// A container service is required if no other connection is provided : Pre-configured Php-Redis Client
// service from the container.
'service' => 'my-service',
]
],
'connection' => [
'type' => 'redis',
'namespace' => 'my-namespace', // Optional : Namespace
'prefix' => 'prefix_', // Optional : Prefix. If a Namespace is configured and the adapter supports it, the Namespace will me used instead.
'logger' => 'my-logger', // Optional : PSR-1 Logger Service Name
'options' => [
// Required if no service is provided : server(s)
'server' => [
'host' => '127.0.0.1', // Required : Hostname
'port' => 6379, // Optional : Port (Default: 6379)
'timeout' => 0.0, // Optional : Timeout (Default: 0.0)
'persistent' => true, // Optional : Use persistent connections (Default: true)
'persistentId' => null, // Optional : Persistent Id (Default: 'phpcache')
],
],
],
],
];
Php Cache Docs: Redis PSR-6 Cache pool, (*45)
Void
This is a void implementation of a PSR-6 cache. Other names for this adapter could be Blackhole or Null adapter.
This adapter does not save anything and will always return an empty CacheItem. It is a part of the PHP
Cache organisation. To read about features like tagging and hierarchy support please read the shared
documentation at www.php-cache.com., (*46)
<?php
return [
'caches' => [
'myHandlerName' => [
'type' => 'void',
'namespace' => 'my-namespace', // Optional : Namespace
'prefix' => 'prefix_', // Optional : Prefix. If a Namespace is configured and the adapter supports it, the Namespace will me used instead.
'logger' => 'my-logger', // Optional : PSR-1 Logger Service Name
'options' => [] // No options available,
],
],
];
Php Cache Docs: Void PSR-6 Cache pool, (*47)
Doctrine
This is a PSR-6 cache implementation using Doctrine cache. It is a part of the PHP Cache organisation.
To read about features like tagging and hierarchy support please read the shared documentation at
www.php-cache.com., (*48)
<?php
return [
'caches' => [
'fromService' => [
'type' => 'doctrine',
'prefix' => 'prefix_', // Optional : Prefix. Namespaces are not supported on this adapter.
'logger' => 'my-logger', // Optional : PSR-1 Logger Service Name
'options' => [
'service' => 'my-service', // Required : A pre-configured doctrine cache service name
]
],
],
];
Php Cache Docs: Doctrine PSR-6 Cache pool, (*49)
Chain
This is a PSR-6 cache implementation using a chain of other PSR-6 cache pools. It is a part of the PHP Cache
organisation. To read about features like tagging and hierarchy support please read the shared documentation
at www.php-cache.com., (*50)
<?php
return [
'caches' => [
'fromService' => [
'type' => 'chain',
'logger' => 'my-logger', // Optional : PSR-1 Logger Service Name
'options' => [
'services' => ['service-one', 'service-two'], // Required : An array of pre-configured cache service names
'skipOnFailure' => false, // Optional : If true we will remove a pool form the chain if it fails. (Default: false)
]
],
],
];
Php Cache Docs: PSR-6 Cache pool chain, (*51)