clickalicious / cachingmiddleware
PSR-7 中间件,兼容 PSR-6 缓存。
v1.1.1
2016-04-16 00:21 UTC
Requires
- php: >=5.5.0
- gpupo/cache: ^1.2
- psr/http-message: ^1.0
- shrikeh/teapot: ^1.0
- wandu/http: ^1.6
Requires (Dev)
- cocur/slugify: ^2.1
- phpunit/phpunit: ^4.8
- relay/relay: ^1.1
- symfony/var-dumper: ^2.8
This package is not auto-updated.
Last update: 2024-09-14 18:42:05 UTC
README
这是一个兼容 PSR-6
的 PSR-7
缓存中间件。
目录
特性
- 缓存 PHP 执行循环中产生的几乎所有内容,如
PHP
、HTML
等(...) - 可堆叠到
PSR-7
堆栈,便于集成 - 兼容所有
PSR-6
缓存实现和许多缓存后端 - 高性能(使用分析器开发)
- 轻量级且高质量的代码库(遵循
PSR-1,2,4,7
) - 100%
PSR-7
中间件兼容性 - 100%
PSR-6
缓存兼容性 - 干净且文档齐全的代码
- 单元测试覆盖率高
示例
这是一个在非常简单的环境中开始使用此中间件库的简单示例。将一个 Cache
放入队列,并使用 PSR-6 Cache
(后端为 Filesystem
- 但您也可以使用 Redis
、Memcached
、MySQL
或任何其他实现 PSR-6
缓存层的后端 ...)
/** * Fill queue for running "Caching Middleware" * * @param \Psr\Http\Message\ServerRequestInterface $request Request (PSR) to process * @param \Psr\Http\Message\ResponseInterface $response Response (PSR) to use * @param callable $next Next middleware in stack * * @return \Psr\Http\Message\ResponseInterface A PSR compatible response */ $queue[] = function (Request $request, Response $response, callable $next) { // Create cache item factory $cacheItemFactory = function ($key) { return new CacheItem($key); }; // Create cache item key factory $cacheItemKeyFactory = function (Request $request) { static $key = null; if (null === $key) { $uri = $request->getUri(); $slugify = new Slugify(); $key = $slugify->slugify(trim($uri->getPath(), '/').($uri->getQuery() ? '?'.$uri->getQuery() : '')); } return $key; }; // Get cache $cachingMiddleWare = new Clickalicious\Caching\Middleware\Cache( new CacheItemPool('Filesystem'), $cacheItemFactory, $cacheItemKeyFactory ); return $cachingMiddleWare($request, $response, $next); };
要求
PHP >= 5.6
(兼容至版本7.2
以及HHVM
)
哲学
Caching Middleware
是一个基于 PSR-6
兼容缓存实现的 PSR-7
兼容中间件。 Caching Middleware
不是独角兽 - 它很好,但随着时间的推移可能会发生变化。尝试它,运行它 ... ♥ 它 ;)
版本管理
为了保持一致的版本管理,我们决定采用 Semantic Versioning 2.0.0
http://semver.org。它易于理解,非常普遍,并从许多其他软件项目中得知。
路线图
- 缓存整个响应,而不仅仅是渲染的 HTML(例如,还包括头信息)
- 将 flysystem 实现为
PSR-Cache
的驱动程序
安全问题
如果您遇到(潜在的)安全问题,请不要犹豫,在向公众发布之前与我们联系 opensource@clickalicious.de
。这样我就可以在问题被共享之前准备并发布更新。谢谢!
参与并分享
... 嗯。如果您也是一个代码猴子 - 也许我们可以建立一个力量 ;) 如果您想参与 代码、评论、文档、维基、错误报告、单元测试、错误修复、反馈 和/或 批评,也请告诉我们!
赞助商
感谢我们的赞助商和支持者