validus / cache
为您的 Expressive 项目提供缓存。
v1.1
2018-10-09 21:52 UTC
Requires
- php: ^7.1
- psr/cache: ^1.0
- psr/container: ^1.0
- psr/http-server-middleware: ^1.0
- psr/simple-cache: ^1.0
- symfony/cache: ^4.1
Requires (Dev)
- doctrine/dbal: ^2.8
- php-coveralls/php-coveralls: ^2.1
- phpstan/phpstan: ^0.10.3
- phpstan/phpstan-strict-rules: ^0.10.1
- phpunit/phpunit: ^7.0.1
This package is auto-updated.
Last update: 2024-09-19 08:30:10 UTC
README
为 zend expressive 项目提供缓存实现。
PSR-6 和 PSR-16 缓存工厂,用于 PSR-11,并带有 Zend 配置提供者。
安装
通过 composer 安装此包是最简单的方法。
$ composer require validus/cache
配置
完整的示例配置可以在 example/full-config.php 中找到。请注意,其中的值是默认值,如果您不更改它们,则不需要提供。尽量保持自己的配置尽可能简单。一个简单的配置可以在 example/simple-config.php 中找到。
如果您的应用程序使用 zend-component-installer Composer 插件,则配置已完成;提供的 Validus\Cache\ConfigProvider
已注册缓存服务。
访问缓存适配器
您可以通过容器访问缓存实现。
use Psr\Cache\CacheItemPoolInterface; use Psr\SimpleCache\CacheInterface; // $pool instanceof CacheItemPoolInterface $pool = $container->get(CacheItemPoolInterface::class); // $cache instanceof CacheInterface $cache = $container->get(CacheInterface::class);
中间件
Validus 缓存包附带一个 CacheResetMiddleware
,允许您在每个请求后重置缓存池到其初始状态。
您可以将中间件添加到 config/pipeline.php
文件中,如下所示
$app->pipe(\Validus\Cache\Middleware\CacheResetMiddleware::class);
中间件的工厂已在配置提供者中提供,因此只要您使用 zend-component-installer Composer 插件,您就无需担心这个问题。