wyrihaximus / react-http-middleware-response-cache
为 @reactphp 的 HTTP 服务器提供响应缓存中间件
Requires
- php: ^7.2
- lcobucci/clock: ^1.1
- psr/http-message: ^1.0
- react/cache: ^1.0 || 0.6 || ^0.5.0
- react/http: ^0.8.0
- react/promise: ^2.7
- wyrihaximus/msgpack: ^1.0
Requires (Dev)
- ringcentral/psr7: ^1.2
- wyrihaximus/async-test-utilities: ^1.1
This package is auto-updated.
Last update: 2024-09-05 10:21:24 UTC
README
安装
要通过 Composer 安装,请使用以下命令,它将自动检测最新版本并将其绑定到 ^
。
composer require wyrihaximus/react-http-middleware-response-cache
此中间件会缓存给定 URL 列表中的响应代码和主体。请注意,目前不会缓存任何头部信息。中间件接受一个实现 CacheConfigurationInterface
的缓存配置作为第一个参数,这将决定何时以及在缓存中存储什么。作为第二个参数,它接受一个实现 CacheInterface
的缓存,可以是随 react/cache
一起提供的 ArrayCache
,或者任何实现 CacheInterface
的缓存,这些缓存实现可在 ReactPHP 用户维基 列表中找到。
用法
$server = new Server([ /** Other middleware */ new ResponseCacheMiddleware( new CacheConfiguration( [ '/', '/robots.txt', '/favicon.ico', '/cache/***', // Anything that starts with /cache/ in the path will be cached '/api/???', // Anything that starts with /cache/ in the path will be cached (query is included in the cache key) ], [ // Optional, array with headers to include in the cache 'Content-Type', ] ), new ArrayCache() // Optional, will default to ArrayCache but any CacheInterface cache will work. ), /** Other middleware */ ]);
会话
使用此中间件与 wyrihaximus/react-http-middleware-session
一起时,请参阅 wyrihaximus/react-http-middleware-response-cache-session-cache-configuration
以确保您不会向具有活动会话的用户提供缓存的响应。
许可证
MIT 许可证 (MIT)
版权所有 (c) 2018 Cees-Jan Kiewiet
特此授予任何获得此软件及其相关文档副本(以下简称“软件”)的人免费使用软件的权利,不受任何限制,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件副本的权利,并允许向软件提供方提供软件的人行使这些权利,前提是遵守以下条件
上述版权声明和本许可声明应包含在软件的所有副本或主要部分中。
软件按“现状”提供,不提供任何明示或暗示的保证,包括但不限于适销性、针对特定目的的适用性和非侵权性保证。在任何情况下,作者或版权所有者均不对任何索赔、损害或其他责任承担责任,无论该责任是基于合同、侵权或其他原因,也不论该索赔、损害或其他责任是否与软件或软件的使用或其他方式有关。