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
的缓存,可以是与 ArrayCache
一起提供的 react/cache
或任何实现 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
在此特此授予任何获得此软件及其相关文档文件(以下简称“软件”)副本的任何人,免费使用该软件而不受限制,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件副本的权利,以及允许向软件提供的人使用该软件的权利,前提是遵守以下条件
上述版权声明和本许可声明应包含在软件的所有副本或主要部分中。
软件按“原样”提供,不提供任何形式的保证,明示或暗示,包括但不限于适销性、针对特定目的的适用性和非侵权性。在任何情况下,作者或版权所有者均不对任何索赔、损害或其他责任负责,无论这些责任是基于合同、侵权或其他原因,无论这些责任源于、因之而起或与软件或其使用或任何其他方式相关。