wshafer / psr11-phpcache
PSR-11 的 PHP 缓存工厂
Requires
- php: ^7.3
- cache/cache: ^1.0
Requires (Dev)
- illuminate/cache: ^5.5
- mongodb/mongodb: ^1.1
- php-coveralls/php-coveralls: ^2.0
- phpmd/phpmd: ^2.8
- phpunit/phpunit: ^9.0.
- predis/predis: ^1.1
- squizlabs/php_codesniffer: ^3.5
- symfony/dependency-injection: ^3.3
This package is auto-updated.
Last update: 2024-09-13 22:15:27 UTC
README
PSR-11 PHP 缓存
PHP Cache 为 PSR-11 提供工厂
目录
安装
composer require wshafer/psr11-phpcache
使用
<?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
更多详细信息请参阅文档
容器
任何 PSR-11 容器都可以使用。为了做到这一点,您需要添加配置并注册 \WShafer\PSR11PhpCache\PhpCacheFactory() 工厂
以下是一些具体的容器示例以供参考
Pimple 示例
// 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 服务管理器
$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 服务管理器
$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) ] ], ], ]);
框架
任何使用 PSR-11 的框架都应该运行良好。以下是一些具体的框架示例以供参考
Zend Expressive
您需要添加配置并注册您希望使用的服务。有几种方法可以实现这一点,但推荐的方法是创建一个新的配置文件 config/autoload/cache.global.php
配置
config/autoload/cache.global.php
<?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
您需要添加配置并注册您希望使用的服务。有几种方法可以实现这一点,但推荐的方法是创建一个新的配置文件 config/autoload/cache.global.php
配置
config/autoload/cache.global.php
<?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
您需要添加配置并注册您希望使用的服务。有几种方法可以实现这一点,但推荐的方法是创建一个新的配置文件 config/autoload/cache.global.php
配置
config/autoload/cache.global.php
<?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 组件安装程序,您还需要注册模块。
config/modules.config.php (ZF 3 框架)
<?php return [ // ... Previously registered modules here 'WShafer\\PSR11PhpCache', ];
config/application.config.php (ZF 2 框架)
<?php return [ 'modules' => [ // ... Previously registered modules here 'WShafer\\PSR11PhpCache', ] ];
Slim
public/index.php
<?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); };
配置
-
命名服务:这些是与工厂相连的服务名称。配置将根据所使用的容器/框架类型而有所不同。
-
适配器:缓存池配置告诉我们使用哪种类型的缓存以及如何连接到该缓存。某些缓存提供了其他特殊选项,用于处理数据和要处理的数据。请参阅下面的适配器配置。
最小配置
最小配置至少应包括一个默认缓存和一个命名服务。请注意,如果您没有指定默认缓存,则在连接默认缓存时将使用无缓存池。
最小示例(使用 Zend Expressive 作为示例)
<?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 ], ], ];
完整配置(使用 Zend Expressive 作为示例)
完整示例
<?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) ] ], ], ];
适配器
APC
这是一个使用 Apc 的 PSR-6 缓存实现。它是 PHP Cache 组织的一部分。要了解有关标记和层次结构支持的特性,请阅读 www.php-cache.com 上的共享文档。
注意:APC 扩展在 PHP 7 中不支持。您可以在 PHP 7 中使用 APC_BC 软件包来实现 APCU 向后兼容性,但建议您使用下面的 APCu 缓存。
<?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 文档: Apc PSR-6 Cache pool
APCU
这是一个使用Apcu实现的PSR-6缓存解决方案。它是PHP Cache组织的一部分。有关标签和层次结构支持等特性的信息,请参阅www.php-cache.com上的共享文档。
<?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缓存文档:Apcu PSR-6 Cache池
数组
这是一个使用PHP数组实现的PSR-6缓存解决方案。它是PHP Cache组织的一部分。有关标签和层次结构支持等特性的信息,请参阅www.php-cache.com上的共享文档。
<?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缓存文档:Array PSR-6 Cache池
文件系统
这是一个使用Filesystem实现的PSR-6缓存解决方案。它是PHP Cache组织的一部分。有关标签和层次结构支持等特性的信息,请参阅www.php-cache.com上的共享文档。
此实现使用出色的Flysystem。
参见:PSR-11 FlySystem,以获取一些预构建的工厂,快速启动和运行
<?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缓存文档:Filesystem PSR-6 Cache池
Illuminate
这是一个使用Illuminate缓存实现的PSR-6缓存解决方案。它是PHP Cache组织的一部分。有关标签和层次结构支持等特性的信息,请参阅www.php-cache.com上的共享文档。
这是一个PSR-6到Illuminate的桥梁。
<?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缓存文档:Illuminate PSR-6 Cache池
Memcache
此适配器不受此包支持,因为没有为PHP 7发布此驱动程序的官方版本。请改用Memcached适配器。
Memcached
这是一个使用Memcached实现的PSR-6缓存解决方案。它是PHP Cache组织的一部分。有关标签和层次结构支持等特性的信息,请参阅www.php-cache.com上的共享文档。
<?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: https://php.ac.cn/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缓存文档:Memcached PSR-6 Cache池
MongoDb
这是一个使用MongoDB实现的PSR-6缓存解决方案。它是PHP Cache组织的一部分。有关标签和层次结构支持等特性的信息,请参阅www.php-cache.com上的共享文档。
<?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缓存文档:MongoDB PSR-6 Cache池
Predis
这是一个使用Predis实现的PSR-6缓存解决方案。它是PHP Cache组织的一部分。有关标签和层次结构支持等特性的信息,请参阅www.php-cache.com上的共享文档。
此实现使用Predis。如果您需要具有PhpRedis的适配器,请查看我们的Redis适配器。
<?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'], ], ] ], ];
注意:有关更多连接选项,请参阅Predis文档。
PHP缓存文档:Predis PSR-6 Cache池
Redis
这是一个使用Redis实现的PSR-6缓存。它是PHP Cache组织的一部分。有关标签和层次结构支持等功能的说明,请阅读www.php-cache.com上的共享文档。
此实现使用PhpRedis。如果您需要一个具有Predis的适配器,请查看我们的Predis适配器。
<?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 文档:Redis PSR-6 Cache pool
无
这是一个PSR-6缓存的空实现。此适配器的其他名称可以是黑洞或空适配器。此适配器不会保存任何内容,并且始终返回一个空的CacheItem。它是PHP Cache组织的一部分。有关标签和层次结构支持等功能的说明,请阅读www.php-cache.com上的共享文档。
<?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 文档:Void PSR-6 Cache pool
Doctrine
这是一个使用Doctrine缓存实现的PSR-6缓存。它是PHP Cache组织的一部分。有关标签和层次结构支持等功能的说明,请阅读www.php-cache.com上的共享文档。
<?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 文档:Doctrine PSR-6 Cache pool
链
这是一个使用其他PSR-6缓存池链实现的PSR-6缓存。它是PHP Cache组织的一部分。有关标签和层次结构支持等功能的说明,请阅读www.php-cache.com上的共享文档。
<?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 文档:PSR-6 Cache pool chain