wpjscc/react-http-middleware-response-cache

用于 @reactphp 的 HTTP 服务器的响应缓存中间件

v1.0.0 2023-11-02 13:38 UTC

This package is auto-updated.

Last update: 2024-08-31 00:26:59 UTC


README

Build Status Latest Stable Version Total Downloads Code Coverage License PHP 7 ready

安装

要通过 Composer 安装,请使用以下命令,它将自动检测最新版本并将其绑定到 ^

composer require wpjscc/react-http-middleware-response-cache

此中间件会缓存给定 URL 列表中的响应代码和主体。注意,目前不会缓存任何头部。中间件接受一个实现 CacheConfigurationInterface 的缓存配置作为第一个参数,这将决定何时将内容存储在缓存中以及存储什么。作为第二个参数,它接受一个实现 CacheInterface 的缓存,可以是与 react/cache 一起提供的 ArrayCache,或者来自 缓存实现 的任何实现,这些实现列在 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.
        null,
        [
            'stream_support' => true,
        ]
    ),
    /** Other middleware */
]);

会话

如果您要使用此中间件与 wyrihaximus/react-http-middleware-session 一起,请查看 wyrihaximus/react-http-middleware-response-cache-session-cache-configuration 以确保您不会向具有活动会话的用户提供缓存响应。

许可证

MIT 许可证 (MIT)

版权所有 (c) 2018 Cees-Jan Kiewiet

特此授予任何人免费获得本软件及其相关文档文件(“软件”)的副本的权利,以便在不受限制的情况下处理软件,包括但不限于使用、复制、修改、合并、发布、分发、转授和/或销售软件的副本,并允许获得软件的人这样做,前提是遵守以下条件

上述版权声明和本许可声明应包含在软件的所有副本或主要部分中。

软件按“现状”提供,不提供任何保证,无论是明示的还是暗示的,包括但不限于适销性、特定用途的适用性和非侵权性。在任何情况下,作者或版权所有者均不对任何索赔、损害或其他责任负责,无论此类责任是基于合同、侵权或其他方式,源自、因或与软件或软件的使用或其他操作有关。